Skip to content

avoid allocation of closures - #23564

Open
rainers wants to merge 1 commit into
dlang:masterfrom
rainers:closure_alloc
Open

avoid allocation of closures#23564
rainers wants to merge 1 commit into
dlang:masterfrom
rainers:closure_alloc

Conversation

@rainers

@rainers rainers commented Aug 9, 2026

Copy link
Copy Markdown
Member

While debugging #23557 I noticed quite a few closure allocations happen during compilation. I guess these are unexpected in dmd, so let's get rid of them.

The assert in BumpGC.malloc triggers for such an allocation in debug builds, maybe it needs to be versioned for older host compiler versions or other backends that don't yet fully support the templated new.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

DMD perf check

Metric Base PR delta
compile hello.d (instr) 216.1 M 215.6 M -0.22%
compile hello.d -O (instr) 234.6 M 234.1 M -0.21%
compile Phobos (instr) 5,137.2 M 5,110.8 M -0.51%
compile Phobos codegen (instr) 1,474.6 M 1,472.4 M -0.15%
compile vibe.d (instr) 15,161.3 M 15,081.3 M -0.53%
dmd binary size (stripped) 6.92 MB 6.95 MB +0.34%
hello binary size 0.72 MB 0.72 MB 0.00%
peak RSS (compile hello.d) 44 MB 43 MB -0.24%
peak RSS (compile Phobos) 639 MB 618 MB -3.24%
peak RSS (compile vibe.d) 1980 MB 1916 MB -3.28%

@rainers

rainers commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Unfortunately, inferring scope for local functions regressed somewhere around dmd 2.101. I happened to have built with dmd 2.095, current versions need a lot more patches. Probably the regression should be fixed first.

@rainers

rainers commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Unfortunately, inferring scope for local functions regressed somewhere around dmd 2.101. I happened to have built with dmd 2.095, current versions need a lot more patches. Probably the regression should be fixed first.

Ah, my breakpoint in the BumpGC didn't fire because it is not built with the old versions. So not a regression...

- make delegates `scope`
- capture parameters explicitly for local classes
@rainers

rainers commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

Unfortunately, the diff here fails for hdrgen.d. It's mostly whitespace changes as functions had to be moved into the local class in toCBuffer, plus ref parameters buf and hgs have to be converted to pointers to capture them explicitly in the class.

Comment thread compiler/src/dmd/hdrgen.d
Comment on lines +981 to +982
extern (C++)
final class DsymbolPrettyPrintVisitor : Visitor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to keep the indentation level the same for most of the diff if you move this class outside of toCBuffer and move its definition to below the class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants