Skip to content

Conversation

@karlseguin
Copy link
Collaborator

Builds on top of #1088

Where #1088 focuses on improve async module loading, this PR improve normal (aka blocking) module loading.

karlseguin and others added 6 commits September 24, 2025 22:28
Allows dynamic imports to be loading asynchronously. I know reddit isnt the
best example, since it doesn't fully load, but this reduced the load time from
~7.2s to ~4.8s.
fix typos

Co-authored-by: Pierre Tachoire <pierre@lightpanda.io>
This changes how non-async module loading works. In general, module loading
is triggered by a v8 callback. We ask it to process a module (a <script type=
module>) and then for every module that it depends on, we get a callback. This
callback expects the nested v8.Module instance, so we need to load it then and
there (as opposed to dynamic imports, where we only have to return a promise).

Previously, we solved this by issuing a blocking HTTP get in each callback. The
HTTP loop was able to continuing downloading already-queued resources, but if
a module depended on 20 nested modules, we'd issue 20 blocking gets one after
the other.

Once a module is compiled, we can ask v8 for a list of its dependent module. We
can them immediately start to download all of those modules. We then evaluate
the original module, which will trigger our callback. At this point, we still
need to block and wait for the response, but we've already started the download
and it's much faster. Sure, for the first module, we might need to wait the same
amount of time, but for the other 19, chances are by the time the callback
executes, we already have it downloaded and ready.
@karlseguin karlseguin force-pushed the concurrent_blocking_imports branch from ed458ea to 418dc6f Compare September 26, 2025 08:56
@karlseguin karlseguin marked this pull request as ready for review September 26, 2025 08:57
@karlseguin karlseguin merged commit 20cb6cd into main Sep 30, 2025
19 checks passed
@karlseguin karlseguin deleted the concurrent_blocking_imports branch September 30, 2025 04:30
@github-actions github-actions bot locked and limited conversation to collaborators Sep 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants