www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19896] New: [internals] Represent string and arrays as sparse

https://issues.dlang.org/show_bug.cgi?id=19896

          Issue ID: 19896
           Summary: [internals] Represent string and arrays as sparse
                    literals
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

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;
    }
  ]
}

--
May 23 2019