Skip to content

align allocations according to the actual type alignment, not an unconditional 16 - #23557

Open
rainers wants to merge 5 commits into
dlang:masterfrom
rainers:allocate_alignment
Open

align allocations according to the actual type alignment, not an unconditional 16#23557
rainers wants to merge 5 commits into
dlang:masterfrom
rainers:allocate_alignment

Conversation

@rainers

@rainers rainers commented Aug 8, 2026

Copy link
Copy Markdown
Member

In my phobos-build-all-unittest this saves about 4% of memory of what the the front end needs.

AFAICT alignment deviates from size_t.sizeof only for IntegerExp when building for 32-bit, though.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

DMD perf check

Metric Base PR delta
compile hello.d (instr) 216.0 M 218.0 M +0.93%
compile hello.d -O (instr) 234.5 M 236.5 M +0.86%
compile Phobos (instr) 5,131.8 M 5,146.4 M +0.28%
compile Phobos codegen (instr) 1,472.9 M 1,474.2 M +0.09%
compile vibe.d (instr) 15,146.4 M 15,183.1 M +0.24%
dmd binary size (stripped) 6.92 MB 6.95 MB +0.40%
hello binary size 0.72 MB 0.72 MB 0.00%
peak RSS (compile hello.d) 44 MB 43 MB -1.69%
peak RSS (compile Phobos) 639 MB 625 MB -2.26%
peak RSS (compile vibe.d) 1982 MB 1937 MB -2.24%

@rainers
rainers force-pushed the allocate_alignment branch from 0bd05c6 to ca4ddd0 Compare August 8, 2026 08:47
@rainers

rainers commented Aug 8, 2026

Copy link
Copy Markdown
Member Author

@thewilsonator Please wait with merging. I will investigate whether the measured 1% compile time increase is legit. If it is it might not be worth the memory savings of less than 2% (the overall memory includes the backend that uses about 30% of process memory in my tests).

@rainers rainers changed the title align allocations according to the actual type alignment, not an unconditional 16 WIP: align allocations according to the actual type alignment, not an unconditional 16 Aug 8, 2026
@rainers
rainers force-pushed the allocate_alignment branch from 173578e to 978a0da Compare August 9, 2026 07:36
@rainers

rainers commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

I cannot reproduce locally as results on a mobile processor tend to vary pretty much. From the last test here, the performance drop seems to come from the virtual call of TypeInfo.talign() to get the proper alignment. Unfortunately I've been falling into the trap that TypeInfo_Class.talign() does not provide the alignment of the instance, but only the reference. The instance alignment is nowhere to be found in the TypeInfo.

So for instances of new SomeClass, an alignment of 8 is assumed now. This keeps the memory savings, but also provides slightly better performance (~1%).

@rainers rainers changed the title WIP: align allocations according to the actual type alignment, not an unconditional 16 align allocations according to the actual type alignment, not an unconditional 16 Aug 9, 2026
@rainers
rainers force-pushed the allocate_alignment branch from 978a0da to 4da91c3 Compare August 9, 2026 07:51
@thewilsonator

Copy link
Copy Markdown
Contributor

ping when this is good

@rainers

rainers commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

an alignment of 8 is assumed now.

Unfortunately on posix, real.alignof is 16, and that's used in RealExp and ComplexExp. So I added a register function for large alignments. Let's see how this performs.

@rainers
rainers force-pushed the allocate_alignment branch from 0315149 to 303e051 Compare August 9, 2026 16:12
@rainers
rainers force-pushed the allocate_alignment branch from ad21c14 to dcb61d6 Compare August 9, 2026 19:19
@rainers
rainers force-pushed the allocate_alignment branch from a5d0ee8 to 28ac80d Compare August 11, 2026 06:41
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