DMD and GDC are unnecessarily using heap allocations for closures

Siarhei Siamashka siarhei.siamashka at gmail.com
Mon May 30 10:24:12 UTC 2022


On Monday, 30 May 2022 at 07:42:29 UTC, user1234 wrote:
> maybe `private long binary_search(long n, long val, long 
> i){...}` will make think other compilers that the stuff is only 
> used localy ?

The code can be massaged in various ways to reduce the allocation 
overhead. For example, the whole 'binary_search' function is not 
necessary and the code from it can be manually inlined (this 
reduces the allocation penalty).

So far I'm quite happy about the quality of the code generated by 
LDC and it has never failed me. But I wonder if the @nogc 
attribute can play a bit nicer with the GC2Stack IR optimization 
pass? For example, somehow postpone the error reporting in the 
frontend and only fail if GC2Stack is actually unable to 
eliminate all GC allocations in the @nogc code. Maybe I can 
report this to LDC developers.

Not sure if anything can be done about GDC. Iain does not seem to 
appreciate reports of this kind in GCC bugzilla and I don't want 
to annoy him unnecessarily.


More information about the Digitalmars-d mailing list