Keeping the JIT gods happy since circa 2015
How much faster? At the time this README was written, decoding scala.js.map took:
v8: 126.96.36.199 node: 5.0.0 os: 10.10.3 hw: 2.5 GHz Intel Core i7, 16gb
First we will need to have our
sourceMap.mappings stored as a buffer. We have
future plans to work directly on a sourceMap buffer, as that will allow for
more ideal performance. Even without, the performance improvements are still
well worth it.
var buffer = /* try to leave the map inert, and in buffer form. Otherwise convert to buffer */
Typically, the following steps are required:
Setup the reader
The reader can read mappings from any array of ascii values. We will use Uint8Array in this example.
let map = JSON;let byteArray = mapmappingslength;let buffer = Buffer;buffer;const SM = ;let reader = byteArray 0 byteArraylength;
Setup the decoder
let decoder = ;let mappingsDecoder = decoder;
Now for some actual decoding
mappingsDecoder;decodermappings // => is the quickly decoded
To concatenate multiple source maps
const decodeFile = SMdecodeFile;let concatenator = ;concatenator;concatenator;concatenator;concatenator; // => the concatenated source maps
Now to reconcatenate the source maps after a source file is removed.
// file-2.js.map is removedconcatenator;concatenator; // => the concatenated source maps
And reconcatenate again after adding back other files.
// an updated file 2 and a new file 4 are addedconcatenator;concatenator;concatenator; // => the concatenated source maps