- Notifications
You must be signed in to change notification settings - Fork 366
Replace _mappings array with data structure #150
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
Conversation
lib/source-map/mapping-list.js Outdated
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.
To justify this unrolling, it provided a slightly over 2x speedup in my testing. Roughly corresponds to the onlyCompareGenerated flag in the util function.
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.
To justify this unrolling, it provided a slightly over 2x speedup in my testing. Roughly corresponds to the onlyCompareGenerated flag in the util function.
Can you add that as a comment then, so it is clear to future readers?
42bf204 to e07a7cd Compare lib/source-map/mapping-list.js Outdated
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.
last -> list ?
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.
Good catch - looks like this code is untested too. Perhaps redact this unused method even?
| Let me know if I should squash the fixup commits |
| Here are the benchmarks I've run so far (couldn't get markdown table to render in comment for some reason, so excuse poor legibility) 1. Data structure performanceThese all use 10,000 mappings. Push to Array only (ie. unsorted at the end)Push to Array then use .sortPush to MappingList then request sorted array2. Overall performance (use generator to produce JSON string)Using Array for _mappingsSorted input Unorted input Using MappingList for _mappingsSorted input Unorted input Using MappingList for _mappings, and skipValidation onSorted input Unorted input |
| Great results, thank you for the detailed benchmarking! Looking at the code now... |
lib/source-map/mapping-list.js Outdated
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.
Nitpick: please wrap comments at column 80
| This looks great! Thank you for taking the time to match the existing style, etc. It is appreciated. Will merge the PR once you rebase+squash and fix up the small comments I had. As a follow up, it seems that once we call |
|
How about Sound about right? |
| Actually |
| The lifetimes are not the same because as soon as you give out the internal array, the instance is invalidated. If we had something like rust's immutable borrows, then maybe not, but... I like |
| Actually, think we should abort this last change - it's a breaking change (see |
|
|
| Well, repeated calls to serialize the generator would reuse the _mapping instance, so more work would be required to decouple their lifetimes. |
| Ah good point. I guess we should just give up on the idea of enforcing safety here then and just trust |
| Think all points have been addressed - let me know if you're satisfied and I'll squash 'em all tomorrow |
| Yup looks good, thanks! Let me know when you've squashed. |
Optimized for best case (called with sorted mappings), with comparable performance otherwise.
ab20944 to 4013c47 Compare | @fitzgen squasherized on latest master |
Replace `SourceMapGenerator.prototype._mappings` array with an optimistic data structure so that adding sorted mappings is faster.
| Thanks! |
| Thanks for the library and thanks for accepting my self-serving amendments :) |
| No problem, 0.1.43 published. |
Leverage the new `skipValidation` flag in `source-map` to disable unneeded safety checks during source map generation. Yields large performance boosts, both passively from using the latest version and additionally from using the flag (see mozilla/source-map#150) Review URL: https://api.github.com/repos/google/traceur-compiler/issues/1620 Closes #1620.
Closes #149
Optimized for best case (called with sorted mappings), with comparable performance otherwise.