Performance improvements: lazy loading, optimized/minimized js bundles etc#350
Performance improvements: lazy loading, optimized/minimized js bundles etc#350richarddd wants to merge 7 commits intosaghul:masterfrom
Conversation
|
Thank you! There is a lot to unpack here :-) I'll take a look this week! I'd like to see this land in multiple PRs. That is, many of the improvements proposed here are not related to the lazy loading and we can land those first before making The Big Change. |
|
Yes I was going to do that originally but then I had to change a couple of things in order to get lazy loading working such as changing some polyfills to ponyfills because they are trying to define properties that I’m currently setting. For example the URL polyfill can’t access globalThis.URL since that’s the property I’m loading and setting (will cause nasty errors and seg faults). |
|
Phew, that was a long read! Before I begin, thanks a ton for doing this! Let's unpack. There is no way I am merging such a large PR, we need to break this down into individual self-contained changes that slowly work towards the end goal, and once all changes are in, it would be virtually equivalent to this PR. I have refrained from making comments while reading the code, because it's just too much to review at once. So, here how I think we can begin to break it down:
Things NOT to do (yet):
All these things can be done under the current internal "architecture". They won't bring that big speedup from the lazy loading, but they'll get us ready-er for it. Now on to the big one. LAZY LOAD ALL THE THINGS! On this step we'd move to lazy loading all the big things. I'd like us to do this in a couple of steps:
An important part for me on this last step, due to the complexity it adds will be to define a way by which we'll measure. Also, how will we know we haven't regressed in startup speed? Perhaps there needs to be a test that checks for this with some baseline, so make sure it stays that way. Hope that makes sense! Happy to work together towards this goal. It'll take a bit of time, but we'll get there. |
|
Yes that sounds like a plan! I'll get to it! One module we also would migrate is the TextEncoder which is terribly slow. And again, the more modules we can move to native the better. I will close this one and work according to the plan :) Thanks for your review! |
|
Awesome! I think the migration to having the stdlib in separate modules (again, lol) and having them lazy-loaded can be done in parallel. Let me know where you plan to start and I can tackle some of the items too. |
I’m currently very limited time wise and will not likely have the bandwidth to do this |
|
👍 sounds good! |
This is a huge PR and basically touches every js file in this project but the startup performance gains are at least 2x.
TODO
tests/test-exec.jstest, all other tests are passing.Lazy loading for all non-essential modules
Almost every module (except native ones) are lazy loaded only when needed. This means that startup performance is at least 2x (often even 3x) faster. For example:
fetch(....)only loads the fetch polyfill and related code when used.Bundle optimizations
console
util.format(lots of code in that module)Blob
path
Future work
Could be moved to C
URL
whatwg-urlimplementation.Future work
Could be optimized using https://uriparser.github.io/
cypto
Other
Native text encoder/decoder
core.textEncodecore.textDecodefrom sys.cImprove script runner
./tjs index.jsvs/tjs run index.js. This "runner" only executes if the first command ends with .js or .cjs or .mjsLinting cleanup
Ran prettier with the correct lint rues throughout the entire project for consistency.
Future work
prettiercode formatting rather than custom ones (double quote strings, indentation etc)