News for hackers. Stuff that matters.
Re:Generics can make your Go code slower by josefx on Wednesday March 30, 2022 @02:03PM (#30858652)
C++ can suffer from negative performance from template bloat in two ways:

Templated symbol names are gigantic. This can impact program link and load times significantly in addition to the inflated binary size.

Duplication of identical code for every type, for example the methods of std::vector<int> and std::vector<unsigned int> should compile to the same instructions. There are linker flags that allow some deduplication but those have their own drawbacks, another trick is to actively use void pointers for code parts that do not need to know the type, allowing them to be reused behind a type safe template based API.

Re:Generics can make your Go code slower by fbkr on Wednesday March 30, 2022 @02:14PM (#30858778)
> There are linker flags that allow some deduplication but those have their own drawbacks

As long as you use --icf=safe I don't see any drawback, and most of the time it results in almost identical reductions to --icf=all since not many real programs compare addresses of functions.

Re:Generics can make your Go code slower by josefx on Wednesday March 30, 2022 @05:15PM (#30860861)
I think that requires separate function sections, which themselves may cause bloat and data duplication.
Re:Generics can make your Go code slower by fbkr on Thursday March 31, 2022 @03:10AM (#30864637)
I, along with everyone in the embedded space, have been using separate function sections forever for --gc-sections and I would be very surprised if they really cause any bloat and duplication at runtime. Do you mean bloat for intermediate files?
Re:Generics can make your Go code slower by josefx on Thursday March 31, 2022 @03:34AM (#30864768)
It may be limited to intermediate files, I assumed that the downside would be bigger since it is not a default and the description mentioned that some things may not be merged as well.