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

[EXPERIMENTAL] Compile records and unions as JS arrays #1316

Closed
wants to merge 2 commits into from

Conversation

alfonsogarciacaro
Copy link
Member

This is an attempt to implement #1308 but with a CompileAsArray attribute. It can be used both for records and unions. Same as Pojo, the types are erased so no reflection, members, etc can be used. Things like JSON serialization haven't been implemented yet. Also note, single case unions have no special handling.

@alfonsogarciacaro
Copy link
Member Author

Some results when compiling new Fulma docs decorating several types with the attribute:

See: Fulma/Fulma@6a17f3f

NORMAL DEV -----------------------------------------------------

Hash: 049066aa2ce598dbd407
Version: webpack 3.10.0
Time: 39097ms
        Asset       Size  Chunks                    Chunk Names
    bundle.js    3.67 MB       0  [emitted]  [big]  main
bundle.js.map       3 MB       0  [emitted]         main
   index.html  913 bytes          [emitted]

COMPILED AS ARRAY DEV ----------------------------------------

Hash: 1e4d0f3f10de1ce40aac
Version: webpack 3.10.0
Time: 72654ms
        Asset       Size  Chunks                    Chunk Names
    bundle.js    3.24 MB       0  [emitted]  [big]  main
bundle.js.map    2.72 MB       0  [emitted]         main
   index.html  913 bytes          [emitted]

NORMAL PROD -----------------------------------------------------

Hash: 81a37bfad06723a886d3
Version: webpack 3.10.0
Time: 145150ms
     Asset       Size  Chunks                    Chunk Names
 bundle.js    1.08 MB       0  [emitted]  [big]  main
index.html  911 bytes          [emitted]

COMPILED AS ARRAY PROD ----------------------------------------

Hash: 239e7f7dffe793ef3c19
Version: webpack 3.10.0
Time: 199650ms
     Asset       Size  Chunks                    Chunk Names
 bundle.js    1.04 MB       0  [emitted]  [big]  main
index.html  911 bytes          [emitted]

NORMAL DEV - REACT EXT - ES2015 --------------------------------

Hash: 6627621591f9a5d753f6
Version: webpack 3.10.0
Time: 34803ms
        Asset     Size  Chunks                    Chunk Names
    bundle.js  2.73 MB       0  [emitted]  [big]  main
bundle.js.map  2.08 MB       0  [emitted]         main
   index.html   1.2 kB          [emitted]

COMPILE AS ARRAY DEV - REACT EXT - ES2015 --------------------------------

Hash: eeb9f3e9af971c4f7553
Version: webpack 3.10.0
Time: 45259ms
        Asset       Size  Chunks                    Chunk Names
    bundle.js    2.33 MB       0  [emitted]  [big]  main
bundle.js.map    1.85 MB       0  [emitted]         main
   index.html  913 bytes          [emitted]

NORMAL PROD - REACT EXT ------------------------------------------------------

Hash: df2a5af26f2acd9338b2
Version: webpack 3.10.0
Time: 50421ms
     Asset     Size  Chunks                    Chunk Names
 bundle.js   976 kB       0  [emitted]  [big]  main
index.html  1.19 kB          [emitted]

COMPILE AS ARRAY PROD - REACT EXT ------------------------------------------------------

Hash: 5ed382321faedf1bfb89
Version: webpack 3.10.0
Time: 47196ms
     Asset     Size  Chunks                    Chunk Names
 bundle.js   938 kB       0  [emitted]  [big]  main
index.html  1.13 kB          [emitted]

@MangelMaxime
Copy link
Member

This look promising. 👍

And I am in favor of not making a special case of single case unions

@alfonsogarciacaro
Copy link
Member Author

Decorating also options and inlining default options we can rip almost 100KB off 😸 Fulma/Fulma@dfb2497

COMPILE AS ARRAY PROD - INLINE DEFAULT OPTS - REACT EXT --------------------------------

Hash: 6b89d7fb74891f5bf977
Version: webpack 3.10.0
Time: 106732ms
     Asset     Size  Chunks                    Chunk Names
 bundle.js   881 kB       0  [emitted]  [big]  main
index.html  1.13 kB          [emitted]

@ncave
Copy link
Collaborator

ncave commented Jan 9, 2018

@alfonsogarciacaro Looks promising, there must be some performace implications if we're shaving so much. Can this be available as a compiler option so we don't have to change source? It's the old compiler option vs attribute argument, but why not have both (when it's ready to be experimented with, of course).

@alfonsogarciacaro
Copy link
Member Author

@ncave This is a bit tricky right now, because CompileAsArray types are erased at runtime (same as Pojo types) so you cannot have members, reflection, etc. Because of this, it's difficult to just automatically apply the attribute to all types in a project.

However, it would be possible to move the compiler in this direction and put members and reflection info in functions on the containing module (which is actually what the F# compiler does). This would have other implications though, I will open a different issue for discussion 👍

@alfonsogarciacaro
Copy link
Member Author

This is already implemented in dev2.0 so we can close this.

@alfonsogarciacaro alfonsogarciacaro deleted the compile-as-array branch July 31, 2018 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants