Skip to content

reduce size of Array!T from 32 to 16 bytes - #23404

Merged
thewilsonator merged 3 commits into
dlang:masterfrom
rainers:array_union
Jul 18, 2026
Merged

reduce size of Array!T from 32 to 16 bytes#23404
thewilsonator merged 3 commits into
dlang:masterfrom
rainers:array_union

Conversation

@rainers

@rainers rainers commented Jul 16, 2026

Copy link
Copy Markdown
Member
  • allocates a maximum of uint.max entries (source code locations are limited to that as well)
  • overlaps single entry with pointer to array of more entries

With my test case of building all phobos unittests with a single invocation (Win64 dmd built with ldc), this reduces the process memory from 18399 MB to 17616 MB, so almost 5% less memory. Note that compiling with -o- uses about 5 GB less memory, so that part is used by the glue layer and backend.

One downside is that the struct is not as digestible in a debugger as before.
The C++ header is not yet adapted, making length a function might be annoying for GDC and LDC.

Let's see what the performance tester reports...

@rainers
rainers force-pushed the array_union branch 3 times, most recently from aa6facc to d00ed6e Compare July 16, 2026 20:25
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

DMD perf check

Metric Base PR delta
compile hello.d (instr) 216.2 M 215.5 M -0.32%
compile hello.d -O (instr) 234.7 M 234.0 M -0.30%
dmd binary size (stripped) 6.86 MB 6.87 MB +0.17%
hello binary size 0.72 MB 0.72 MB 0.00%
peak RSS (compile hello.d) 46 MB 44 MB -4.84%

@rainers
rainers force-pushed the array_union branch 2 times, most recently from dc484ba to 89b9146 Compare July 16, 2026 20:48
@thewilsonator
thewilsonator marked this pull request as draft July 16, 2026 23:18
Comment thread compiler/src/dmd/doc.d
// build the template parameters
Array!(size_t) paramLens;
paramLens.reserve(td.parameters.length);
paramLens.setDim(td.parameters.length);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was an actual bug uncovered by this PR, as reserve leaves the array empty in the foreach loop below.

@thewilsonator

Copy link
Copy Markdown
Contributor

Is this good to go?

@rainers
rainers marked this pull request as ready for review July 18, 2026 09:16
@rainers
rainers requested a review from ibuclaw as a code owner July 18, 2026 09:16
@rainers rainers changed the title Draft: reduce size of Array!T from 32 to 16 bytes reduce size of Array!T from 32 to 16 bytes Jul 18, 2026

@thewilsonator thewilsonator left a comment

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.

Otherwise looks good.

Comment thread compiler/src/dmd/backend/arm/disasmarm.d Outdated
@rainers

rainers commented Jul 18, 2026

Copy link
Copy Markdown
Member Author

Is this good to go?

I have restored/updated comments now. Should be fine.

One downside is that the struct is not as digestible in a debugger as before.

For the mago-extension you can define

extern (D) T[] __debugExpanded() { return opSlice(); }

to show the array elements in the VS debugger. Ok to add this? Maybe just for version Debugger_friendly already used for BitFields.

The C++ header is not yet adapted, making length a function might be annoying for GDC and LDC.

Changed back to a field, but just uint instead of size_t. Hopefully does not cause issues for LDC or GDC.

rainers added 3 commits July 18, 2026 11:36
- allocates a maximum of uint.max entries
- overlaps single entry with pointer to array
@thewilsonator
thewilsonator merged commit f1266b6 into dlang:master Jul 18, 2026
42 checks passed
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