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: nob...@puremagic.com
          Reporter: ibuc...@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;
    }
  ]
}

--

Reply via email to