Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 369
Use WebAssembly to speed up SourceMapConsumer#306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f0e742045c04ed38e98f4084ba13e652d65367356cf76c60b6ca73c7c4aa0a3e80a40bb90fa03d395699bd9fdc48b10e38fa87d4be222ef62fbfb52b2b4adc7b8e6da2621835488686af676051338b341f25ff9215eab8bb3b00f03b61129353d481ab311fdab43cc4a858570b4903b3a3c7e13d99cfc58b8f2ff5e866b7a77ecfa0ce3e7041b8d8253c566aa3d7d943b664b359fab43ef24a0480d2199f878008File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,3 +2,6 @@ | ||
| *.log | ||
| .idea | ||
| node_modules/* | ||
| build/ | ||
| package-lock.json | ||
| bench/*.svg | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,11 +3,8 @@ language: node_js | ||
| sudo: false | ||
| node_js: | ||
| - "0.10" | ||
| - "0.12" | ||
| - "4" | ||
| - "5" | ||
| - "6" | ||
| - "8" | ||
| - "9" | ||
| cache: | ||
| directories: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,7 +32,9 @@ This is a library to generate and consume the source map format | ||
| - [With SourceMapGenerator (low level API)](#with-sourcemapgenerator-low-level-api) | ||
| - [API](#api) | ||
| - [SourceMapConsumer](#sourcemapconsumer) | ||
| - [SourceMapConsumer.initialize(options)](#sourcemapconsumerinitializeoptions) | ||
| - [new SourceMapConsumer(rawSourceMap)](#new-sourcemapconsumerrawsourcemap) | ||
| - [SourceMapConsumer.prototype.destroy()](#sourcemapconsumerprototypedestroy) | ||
| - [SourceMapConsumer.prototype.computeColumnSpans()](#sourcemapconsumerprototypecomputecolumnspans) | ||
| - [SourceMapConsumer.prototype.originalPositionFor(generatedPosition)](#sourcemapconsumerprototypeoriginalpositionforgeneratedposition) | ||
| - [SourceMapConsumer.prototype.generatedPositionFor(originalPosition)](#sourcemapconsumerprototypegeneratedpositionfororiginalposition) | ||
| @@ -67,7 +69,7 @@ This is a library to generate and consume the source map format | ||
| ### Consuming a source map | ||
| ```js | ||
| var rawSourceMap = { | ||
| const rawSourceMap = { | ||
| version: 3, | ||
| file: 'min.js', | ||
| names: ['bar', 'baz', 'n'], | ||
| @@ -76,7 +78,7 @@ var rawSourceMap = { | ||
| mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' | ||
| }; | ||
| var smc = new SourceMapConsumer(rawSourceMap); | ||
| const smc = await new SourceMapConsumer(rawSourceMap); | ||
| console.log(smc.sources); | ||
| // [ 'http://example.com/www/js/one.js', | ||
| @@ -101,6 +103,9 @@ console.log(smc.generatedPositionFor({ | ||
| smc.eachMapping(function (m) { | ||
| // ... | ||
| }); | ||
| // Free the SourceMapConsumer's manually managed wasm data. | ||
| smc.destroy(); | ||
| ``` | ||
| ### Generating a source map | ||
| @@ -182,10 +187,27 @@ const sourceMap = require("devtools/toolkit/sourcemap/source-map.js"); | ||
| ### SourceMapConsumer | ||
| A SourceMapConsumer instance represents a parsed source map which we can query | ||
| A `SourceMapConsumer` instance represents a parsed source map which we can query | ||
| for information about the original file positions by giving it a file position | ||
| in the generated source. | ||
| #### SourceMapConsumer.initialize(options) | ||
| When using `SourceMapConsumer` outside of node.js, for example on the Web, it | ||
| needs to know from what URL to load `lib/mappings.wasm`. You must inform it by | ||
| calling `initialize` before constructing any `SourceMapConsumer`s. | ||
| The options object has the following properties: | ||
| * `"lib/mappings.wasm"`: A `String` containing the URL of the | ||
| `lib/mappings.wasm` file. | ||
| ```js | ||
| sourceMap.SourceMapConsumer.initialize({ | ||
| "lib/mappings.wasm": "https://example.com/source-map/lib/mappings.wasm" | ||
| }); | ||
| ``` | ||
| #### new SourceMapConsumer(rawSourceMap) | ||
| The only parameter is the raw source map (either as a string which can be | ||
| @@ -207,8 +229,23 @@ following attributes: | ||
| * `file`: Optional. The generated filename this source map is associated with. | ||
| The promise of the constructed souce map consumer is returned. | ||
| When the `SourceMapConsumer` will no longer be used anymore, you must call its | ||
| `destroy` method. | ||
| ```js | ||
| const consumer = await new sourceMap.SourceMapConsumer(rawSourceMapJsonData); | ||
| doStuffWith(consumer); | ||
| consumer.destroy(); | ||
| ``` | ||
| #### SourceMapConsumer.prototype.destroy() | ||
| Free this source map consumer's associated wasm data that is manually-managed. | ||
| ```js | ||
| var consumer = new sourceMap.SourceMapConsumer(rawSourceMapJsonData); | ||
| consumer.destroy(); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bummer but I guess there's no good way around it. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have ideas to improve this in follow ups: Either add an async RAII-ish function like: SourceMapConsumer.with=asyncfunction(rawSourceMap,f){constconsumer=awaitnewSourceMapConsumer(rawSourceMap);try{awaitf(consumer);}finally{consumer.destroy();}};Or alternatively give every | ||
| ``` | ||
| #### SourceMapConsumer.prototype.computeColumnSpans() | ||
| @@ -239,7 +276,6 @@ consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" }) | ||
| // { line: 2, | ||
| // column: 20, | ||
| // lastColumn: Infinity } ] | ||
| ``` | ||
| #### SourceMapConsumer.prototype.originalPositionFor(generatedPosition) | ||
| @@ -579,9 +615,9 @@ Creates a SourceNode from generated code and a SourceMapConsumer. | ||
| should be relative to. | ||
| ```js | ||
| var consumer = new SourceMapConsumer(fs.readFileSync("path/to/my-file.js.map", "utf8")); | ||
| var node = SourceNode.fromStringWithSourceMap(fs.readFileSync("path/to/my-file.js"), | ||
| consumer); | ||
| const consumer = await new SourceMapConsumer(fs.readFileSync("path/to/my-file.js.map", "utf8")); | ||
| onst node = SourceNode.fromStringWithSourceMap(fs.readFileSync("path/to/my-file.js"), | ||
| consumer); | ||
| ``` | ||
| #### SourceNode.prototype.add(chunk) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.csv |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,20 @@ | ||
| # Benchmarking | ||
| This directory contains helpers for benchmarking (1) parsing, and (2) generating | ||
| source maps. | ||
| This directory contains helpers for benchmarking the `mozilla/source-map` | ||
| library. | ||
| Ensure that you have built the library, as these benchmarks rely on | ||
| `dist/source-map.js`. See the main README.md for detais on building. | ||
| ## Running Within a Browser | ||
| Run a local webserver from the root of the repository: | ||
| Open `bench.html` in a browser and click on the appropriate button. | ||
| ``` | ||
| $ cd source-map/ | ||
| $ python -m SimpleHTTPServer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks | ||
| ``` | ||
| ## Running with a JS Shell | ||
| Open | ||
| [http://localhost:8000/bench/bench.html](http://localhost:8000/bench/bench.html) | ||
| in your browser. | ||
| Run `$JS_SHELL bench-shell-bindings.js`. | ||
| Open `bench.html` in a browser and click on the appropriate button. | ||
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/c-api/wasm-api/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!