-
Notifications
You must be signed in to change notification settings - Fork 60
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
Large output size on jsoo #84
Comments
Hi, @joprice, I don't know what exactly is creating that much code, but in #74 and #90 we're removing direct and transitive dependencies on If you want, you can try yourself by taking the |
Sounds good. I'll try that out when I get a second. |
Short update: both PRs are merged now and scheduled to be released as part of |
I tried out the master branch and I don't see a difference with 1.7.0. However, I am seeing a smaller overall increase from the library of 36k, probably due to optimizations in the newer version jsoo version I'm using since I tried this last year. |
splitting Such change would only improve the size when using separate compilation as jsoo would likely be able to drop theses units during whole program compilation. |
That sounds like a very good idea, I'll try to split these apart. In particular, probably next to nobody will need |
Splitting took a moment since there was some weirdness in there, but here we go: #167 |
After splitting, here is the size (in bytes) of individual units.
Adding a reference to yojson can also force Running a very small experiment, I see that using Yojson.Basic.to_string (assuming CamlinternalFormat is already included) make my program jump from 84k to 129k (+45k). It turns out that the current implementation prevent jsoo from eliminating the (dead code) lexer. I've a patch that makes my experiment jump to 88k only (+4k). |
A deeper look at read.mll, there are 3 lexers/parsers in there (normal, skip and buffer variants) which are duplicated 3 times (for Basic, Safe and Raw modules). It might be possible to reduce logic duplication.
|
Thanks @hhugo for your investigation. I'll try to reduce the duplication a bit next time I get to work on it. I don't think we can remove the reference to |
Just to make sure my comment doesn't get lost in the noise above. #168 allows jsoo to remove lexers if no used. |
CHANGES: *2023-10-10* ### Changed - Make `Basic`, `Safe` & `Raw` seperate compilation units that get exposed by the main module as suggested by @hhugo to enable JSOO to discard unused modules. No API changes should be observable. (ocaml-community/yojson#84, ocaml-community/yojson#167 @Leonidas-from-XIV) - Removed forward refs in the parser to make dead-code elimination in JSOO better (ocaml-community/yojson#168, @hhugo)
CHANGES: *2023-10-10* - Make `Basic`, `Safe` & `Raw` seperate compilation units that get exposed by the main module as suggested by @hhugo to enable JSOO to discard unused modules. No API changes should be observable. (ocaml-community/yojson#84, ocaml-community/yojson#167 @Leonidas-from-XIV) - Removed forward refs in the parser to make dead-code elimination in JSOO better (ocaml-community/yojson#168, @hhugo)
CHANGES: *2023-10-10* - Make `Basic`, `Safe` & `Raw` seperate compilation units that get exposed by the main module as suggested by @hhugo to enable JSOO to discard unused modules. No API changes should be observable. (ocaml-community/yojson#84, ocaml-community/yojson#167 @Leonidas-from-XIV) - Removed forward refs in the parser to make dead-code elimination in JSOO better (ocaml-community/yojson#168, @hhugo)
2.1.1 has been released with all these improvements, thanks for the help! |
CHANGES: *2023-10-10* - Make `Basic`, `Safe` & `Raw` seperate compilation units that get exposed by the main module as suggested by @hhugo to enable JSOO to discard unused modules. No API changes should be observable. (ocaml-community/yojson#84, ocaml-community/yojson#167 @Leonidas-from-XIV) - Removed forward refs in the parser to make dead-code elimination in JSOO better (ocaml-community/yojson#168, @hhugo)
When using this library with jsoo, a single reference to the library adds 64k to the js output. This is 20% of the total size of the application. This happens for instance with just a single definition of a function like
let x = Yojson.Basic.to_string
, with no uses. I'm not sure if this is an issue with jsoo that would require a more advanced optimizer, or with dependencies of the library that could perhaps be reduced to avoid pulling in so much code, but since json is a built-in feature of browsers, one would expect it to have relatively low overhead.The text was updated successfully, but these errors were encountered: