Start downloading all synchronous imports ASAP

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.
This commit is contained in:
Karl Seguin
2025-09-25 18:05:09 +08:00
parent 2aa4b03673
commit 418dc6fdc2
6 changed files with 159 additions and 134 deletions

View File

@@ -693,7 +693,7 @@ const IsolatedWorld = struct {
_ = try self.executor.createJsContext(
&page.window,
page,
{},
null,
false,
Env.GlobalMissingCallback.init(&self.polyfill_loader),
);