Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dart2js: smaller huge const maps #17579

Closed
rakudrama opened this issue Mar 18, 2014 · 2 comments
Closed

dart2js: smaller huge const maps #17579

rakudrama opened this issue Mar 18, 2014 · 2 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dart2js-optimization type-enhancement A request for a change that isn't a bug web-dart2js

Comments

@rakudrama
Copy link
Member

const maps have some redundancy:

const {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}

--->

C.List_8xz = Isolate.makeConstantList(["a", "b", "c", "d", "e"]);
C.Map_8x6Jr = new H.ConstantStringMap(5, {a: 1, b: 2, c: 3, d: 4, e: 5}, C.List_8xz);

  1. The key names are repeated. 2. The length is redundant with respect to the list.

Instead of parsing and constructing the object literal, the JS code could call a helper that takes a keys list and a values list.

C.List_8xz = Isolate.makeConstantList(["a", "b", "c", "d", "e"]);
C.Map_8x6Jr = Isolate.makeConstantStringMap(C.List_8xz, [1, 2, 3, 4, 5]);

The space saving is roughly the accumulated length of the keys, provided 'makeConstantStringMap' is minified.

@floitschG
Copy link
Contributor

Added Optimization label.

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Feb 29, 2016
@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 20, 2019
@rakudrama
Copy link
Member Author

5cbba84 makes a change addressing this issue.

The new constant looks like:

    B.Object_xw8 = {a: 0, b: 1, c: 2, d: 3, e: 4};
    B.Map_Jbsy5 = new A.ConstantStringMap(B.Object_xw8, [1, 2, 3, 4, 5], A.findType("ConstantStringMap<String,int>"));

The refactoring into an index-Object and a values-list allows the index to be shared between similar Maps and Sets.
There is still some redundancy in the representation for a single Map but that is now all small integers in the index rather than potentially lengthy key values. This form also produces better bytecode in V8 in the general case since the index never contains a value that must be inserted programmatically and can be generated by cloning a template (CreateObjectLiteral) with no further property definitions. This helps IPL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dart2js-optimization type-enhancement A request for a change that isn't a bug web-dart2js
Projects
None yet
Development

No branches or pull requests

4 participants