Skip to content

DDC expands existing constants when they are embedded in other constants #37523

@nshahan

Description

@nshahan

Following on from issue #36535 there is still a problem of a code size explosion when a constant is embedded in another constant. Given the following dart code we will generate calls to the const list constructor every time a appears in b.

main() {
  const a = [1];
  const b = [a,a,a];
}

When we dump the dill file we can see that one constant are references the other. Is there a mechanism already built to help us recognize this in the backend and generate better code?

main = tes::main;
library from "file:///Users/nshahan/code/test_files/test_03.dart" as tes {

  static method main() → dynamic {
    const core::List<core::int> a = #C2;
    const core::List<core::List<core::int>> b = #C3;
  }
}
constants  {
  #C1 = 1
  #C2 = <core::int>[#C1]
  #C3 = <core::List<core::int>>[#C2, #C2, #C2]
}

Metadata

Metadata

Assignees

Labels

P0A serious issue requiring immediate resolutionarea-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.legacy-area-front-endLegacy: Use area-dart-model instead.web-dev-compiler

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions