Re:Show HN: Fo: An experimental language which adds generics...
by anonymoushn on Tuesday June 12, 2018 @06:07PM
(#17298516)
Image allows you to do this more or less. The problem to be solved here is that if you write the resize logic just once, you are accessing pixels from the image via the interface in a tight loop, and most of the time taken by your image resizer is the overhead of that access.
[ Parent
| on HN ]
Re:Show HN: Fo: An experimental language which adds generics...
by ereyes01 on Tuesday June 12, 2018 @06:41PM
(#17298737)
Interesting, you have a point actually. I would have thought that the performance cost of calling through an interface would be negligible, but I'm wrong about that:
https://github.com/golang/go/issues/20116
The issues linked at the end there are interesting reads, and maybe they'll do something about this by Go 1.11.
Having said all that, will an implementation of your code with generics be all that much faster? Or slower? Of course, those are not answerable questions in practice with today's tools :-)
Re:Show HN: Fo: An experimental language which adds generics...
by pjmlp on Wednesday June 13, 2018 @12:50AM
(#17300351)
Go 1.11 is already feature freeze and it doesn't seem likely.
Re:Show HN: Fo: An experimental language which adds generics...
by burntsushi on Tuesday June 12, 2018 @09:12PM
(#17299482)
> Having said all that, will an implementation of your code with generics be all that much faster?
Likely yes. If generics are implemented via monomorphization, then you can avoid the overhead of virtual calls necessitated by interfaces.
It is possible that the compiler could become smart enough to devirtualize calls through interfaces.
Re:Show HN: Fo: An experimental language which adds generics...
by weberc2 on Tuesday June 12, 2018 @11:54PM
(#17300113)
Pretty sure devirtualization is a whole program optimization in the general case, and I don’t see the Go dev team Pershing that in the next couple of years.
Re:Show HN: Fo: An experimental language which adds generics...
by burntsushi on Wednesday June 13, 2018 @07:05AM
(#17301979)
> I don’t see the Go dev team Pershing that in the next couple of years
Agreed. But if I didn't mention it, I'm sure someone would have felt obligated to respond with a "well actually..."