Load WASM/JS modules dynamically using importScripts #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Up until now we have been importing the JavaScript-with-embedded-WebAssembly modules statically at build time just like any other TypeScript/JavaScript code. This PR changes this to dynamically import such code on demand using the WebWorker
importScripts
function. There are two benefits:Shell
object, to support arbitrary terminal functionality written by ourselves or any user.To dynamically import such modules they have to be available at some URL. At this stage I have implemented a really simple solution to this in the test suite and cockle-playground (Jupyter terminal extension to follow) of copying the JS/WASM files from the cockle npm package into the webpack/rspack statically-served
assets
directory.The imported JS/WASM modules are cached to make subsequent command calls faster. The first time
coreutils
is used it takes on my dev machine ~150 ms to import compared to the ~60 ms previously. But subsequent calls only take ~15 ms compared to the ~30 ms previously.grep
is faster as it is a much smaller module with just a single command, taking ~60 ms to load the first time and <10 ms subsequently. If these times get worse and feel like they are too long then we can always pre-emptively warm up the cache at the start. Also note that the browser caches the JS/WASM files and if you have a copy ofcoreutils
already cached in the browser it only takes ~60 ms to import the first time.