feat(sourcemapconsumerSync): Synchronous sourcemap consumer interface #369
+2,707
−0
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.
NOT TO BE MERGED: as this is dirty and quick poc, most of codes are duplicated between async interface
This PR aims to discuss viable path to #331, primarily to support synchronous interface to
SourceMapConsumer
relies on wasm binary. There are 2 major places async instantiation involved in SourceMapConsumer:WebAssembly.instantiate
In this changes, exposes new interface named
SourceMapConsumerSync
as non-major-breaking interface, and replaces above logic to sync viaEmbed base64 encoded wasm binary, synchronously read it as buffer
: Inspired by
emscripten
'sSINGLE_FILE=1
option. Instead of resolving physical file (or remote resource forfetch
) includes binary into javascript, allows to read it as arraybuffer synchronously.Replace
WebAssembly.instantiate
toWebAssembly.Module
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module): When bufferSource is already available, it is possible to synchronously instantiate wasm module via
WebAssembly.Module
, then create instance viaWebAssembly.Instance
with importobject.To verify changes, convert-pasted async test cases into sync test cases as well.
Still, this brings number of unanswered q, reason I consider this as rather discussion than to-be-merged PR.
dist/*.js
will bundle wasm binary now, which increases bytesize. I believe Remove the bundled dist/ directory? #362 is way to go and consumer should be able to tree-shake with own bundler config, so this would not be major deal.SourceMapConsumerSync
is just to make poc convinient.Except initialization, most of codes are shared between async to sync interface implementations.
Binary size is fairly small (~60kb), but this is still sync behavior, not sure about impact especially on browser environment. Maybe only support node.js would be feasible since most usecases for sync interface comes from node.js tooling.
Even if I composed this PR, I strongly believe async interface is way to go and if any tools can refactor usage of this module it should be recommended. Not sure about exposing sync interface as escape hatches, as consumer will going to use this interface and won't be easily deprecated.
Thoughts? Ideas? I'm totally ok to close this PR, but wanted to raise it for discussions especially lot of tools I use (i.e
source-map-support
) would like to benefit from faster wasm implementation.