Bug 24343 – Read only data used to initialize objects that are mostly zero

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-01-17T22:41:12Z
Last change time
2024-12-13T19:32:39Z
Keywords
industry, performance
Assigned to
No Owner
Creator
Walter Bright
Moved to GitHub: dmd#18206 →

Comments

Comment #0 by bugzilla — 2024-01-17T22:41:12Z
Consider: struct S { int[100] x; } The compiler generates a static initializer for it. But since it is all zeros, it is allocated in the BSS segment and does not consume any memory in the DATA or READONLY sections in the executable. Even better, since the initializer is readonly, all the zero-initialized objects sit on top of each other in BSS, consuming only the memory used by the largest. When a zero initializer object is initialized, it is done with a memset(). For: struct T { int i = 3; int[100] x; } The initializer is not all zero, so it is placed in the READONLY section. Initialization of an object is performed by doing a memcpy() from this data. The idea of this issue is: 1. the .init data not be generated at all for the T 2. Object initialization should be done by a memset() followed by assignment to the non-zero members. Or simply do memberwise assignment.
Comment #1 by dfj1esp02 — 2024-01-25T19:50:57Z
TypeInfo could have a member --- byte pattern; --- so that struct S { char[100] x; } (sockaddr_un?) could still be initialized with memset.
Comment #2 by johanengelen — 2024-02-23T18:54:51Z
How will this code be treated? ``` const(void[]) f() { return __traits(initSymbol, T); } ```
Comment #3 by robert.schadek — 2024-12-13T19:32:39Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18206 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB