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

Reduce loading time #1073

Merged
merged 11 commits into from
Aug 28, 2023
Merged

Reduce loading time #1073

merged 11 commits into from
Aug 28, 2023

Conversation

mitschabaude
Copy link
Collaborator

@mitschabaude mitschabaude commented Aug 16, 2023

PR to reduce the startup time of SnarkyJS
Closes #1065

Bindings: o1-labs/o1js-bindings#116
Mina: MinaProtocol/mina#13925
Snarky: o1-labs/snarky#829

Benchmark (node):

./run src/examples/benchmarks/import.ts

Time to import at various steps:

Web flame graph of the first ~2 seconds, before:
image

Same flame graph after:
image

Note: There's basically no way to reduce this further within the current architecture. After this PR, most of the loading time of ~0.5sec comes from compiling the JS bundle, which is large. Of the time spent executing that bundle, most happens in core JSOO / OCaml libs. There's only about 50ms of top-level computation caused by Mina code. Some of which is just instantiating modules that we need. There's almost nothing left that we can get rid of.

@mitschabaude mitschabaude marked this pull request as ready for review August 17, 2023 21:25
Copy link
Collaborator Author

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: all the non-trivial changes are in the linked PRs (Mina, bindings, snarky)

@@ -1,3 +1,4 @@
import './bindings/crypto/bindings.js';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, here's how this is supposed to work:

the new bindings.ts file imported here is written in TS, and contains code integrated with our normal codebase. It is exposed to JSOO by populating a global variable with an object. It gets imported as the first thing here so that the global variable is ready by the time JSOO code gets executed.

It may not be the cleanest thing to have an implicit dependency like that, but it's a huge improvement over the status quo, where all JS code used in JSOO has to be part of an ugly file containing outdated syntax which can use neither TS nor normal imports.

@L-as
Copy link

L-as commented Aug 23, 2023

Can't you do the parsing lazily? You could use a dynamic import instead. If you use the separate jsoo compilation, you can maybe even import each separately lazily.

@mitschabaude
Copy link
Collaborator Author

Can't you do the parsing lazily? You could use a dynamic import instead. If you use the separate jsoo compilation, you can maybe even import each separately lazily.

we can (we do) but then you can't use the lib directly after import. we'd get back await isReady

@mitschabaude mitschabaude merged commit 0b4fa9e into main Aug 28, 2023
@mitschabaude mitschabaude deleted the perf/loading-time branch August 28, 2023 19:25
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.

Remove bottlenecks in snarkyjs loading time
5 participants