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
Switch to TraceMap for sourcemap's originalPositionFor API #1181
Conversation
[trace-mapping](https://github.com/jridgewell/trace-mapping) is faster, smaller, and lighter than the `source-map` package, and doesn't require WASM, manual memory management, or async/await to use.
@@ -44,12 +44,11 @@ | |||
"use strict"; | |||
|
|||
import MOZ_SourceMap from "source-map"; |
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.
We still use the SourceMapGenerator
API to generate a new sourcemap for the minified output. TraceMap
(and AnyMap
) are only for consuming and tracing an already existing sourcemap.
@@ -1,2 +1,2 @@ | |||
new function(){console.log(3)}; | |||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFuQyxXQUFjQSxRQUFRQyxJQUFJIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgRm9vIHsgY29uc3RydWN0b3IoKXtjb25zb2xlLmxvZygxKzIpO30gfSBuZXcgRm9vKCk7XG4iXX0= | |||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl19 |
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.
This is a bug in the SourceMapConsumer lookup that's now fixed. There are two segments which both occupy generated column 10. The first has a source column of 10, and the second has a source column of 12. SourceMapConsumer
returned the second segment, where TraceMap
returns the first. This is a difference between the binary search immediately returning, or finding the "lower bound" for conflicting matches.
Co-authored-by: Fábio Santos <fabiosantosart@gmail.com>
I was testing this out earlier, but didn't realize I wasn't actually using the new changes :D |
|
||
// a small wrapper around fitzgen's source-map library | ||
async function SourceMap(options) { |
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.
I think this is the only reason minify
is async right now. I'm wondering if there should be a minifySync
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.
Actually I don't need to wonder much, it was the one thing people asked for when Terser 5 was released.
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.
Would you like me to go through and remove all asyncs?
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.
Not in this PR :)
Also if the minify function becomes sync, it would break people who are calling .then directly. It should be a new function
I'm taking a while to merge this PR because I've been doing some memory testing. When minifying a very large file (a minified dist/bundle.min.js repeated a whole bunch of times until it's 10mb), this PR appears to allocate around 100mb more RAM than master. The memory usage during formatting does not change, but it does change between before and after calling
|
Here are some numbers for a file around half that size -- the speed is better relative to
And here are the file sizes BTW. They're minified by terser which was the easiest way I could think of to create a source map. The run described above is for minifying
|
Here's the data for the 10MB file, for completion:
I noticed that your PR is faster after all so I'm editing the original comment. Don't know how I missed that. |
It seems you're right. I had only ever memory profiled against the non-WASM 0.6.1. I'm going to add memory benchmarks to my readme, but this is the current result:
Because WASM has direct memory access, they can pack the integers extremely tightly, whereas I have to rely on V8's |
I'm a little suspicious this isn't properly detecting memory allocated in the C++ side. In my example above, |
I'm doing a thing that makes this discussion a bit less necessary
I figured that we can destroy the AST as we walk it during the output phase. It works pretty well! |
Yup. Memory allocated by WASM is stored in
So I think |
Hey, that's awesome! I'll merge then :) |
This was incredible work @jridgewell, thank you! |
trace-mapping is faster, smaller, and lighter than the
source-map
package, and doesn't require WASM, manual memory management, or async/await to use.Re: #1164