Bug 19896 – [internals] Represent string and arrays as sparse literals

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-05-23T19:07:11Z
Last change time
2024-12-13T19:03:30Z
Assigned to
No Owner
Creator
Iain Buclaw
Moved to GitHub: dmd#19569 →

Comments

Comment #0 by ibuclaw — 2019-05-23T19:07:11Z
Given the following: --- auto f = cast(char[2147483646]) "ab"; --- In the front-end, the initializer for this array consumes 2GB of memory (multiplied by the number of times it is copied, I count two or three times). StringExp { size = 2147483646; value = "ab\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0..."; } When really, you could get away with only 32 bytes, if the data structure were smarter. StringExp { size = 2147483646; values [ { index = 0; value = 97; }, { index = 1; value = 98; } ] }
Comment #1 by iamthewilsonator — 2019-05-25T11:49:04Z
I think we should be fast and memory efficient for the common case, and most string aren't sparse. What use case is that?
Comment #2 by ibuclaw — 2019-06-10T14:05:25Z
(In reply to Nicholas Wilson from comment #1) > I think we should be fast and memory efficient for the common case, and most > string aren't sparse. What use case is that? I'm willing to admit that StringExp may be the wrong target to try to fix. ArrayLiteralExp's however I won't give up on. Casting a StringExp to any array type shouldn't create a new (potentially bigger) StringExp.
Comment #3 by robert.schadek — 2024-12-13T19:03:30Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19569 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB