-
Notifications
You must be signed in to change notification settings - Fork 188
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
Optimize sourcemap processing #1617
Conversation
25c2733
to
9218fa3
Compare
I can’t seem to reproduce the CI failure:
This test builds fine on my machine. Edit: never mind, it was an off-by-one error in an assertion. |
7ca0b47
to
ac75d97
Compare
One test is failing because reading “index maps” (composite source maps) is not supported for now—something that is not required for js_of_ocaml to function. I will fix this test soon. |
ab355a0
to
64f5df3
Compare
I just tested this change on an incremental build for one of our largest executables and am getting this timing for Pre: 2.469s Very cool! |
ec3ead0
to
3ffa259
Compare
This is ready for review. I don’t quite understand the build problems on the 5.1 CI, but they don’t seem related to this PR. |
01f15f7
to
fb76558
Compare
My bad, it actually was due to a missing |
bfbccf2
to
3b5260a
Compare
3b5260a
to
ae4c709
Compare
Is anything blocking this PR still? |
4e19da9
to
7bbcff7
Compare
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've pushed some minor cleanup on the branch directly.
I think this goes in the right direction.
Changes would be easier to digest if they were in separate commits.
My understanding is that the Line_edits change is what gives use the most part of the improvement. Could we achieve similar perf using sections (Index sourcemap) ?
I’m trying to answer some of your comments but my answers are labelled as “pending”, I’m not sure why. |
Never mind, apparently I had started a review at some point in the past and never completed it, and apparently Github considers all your comments henceforth as pending |
Just to make sure we are on the same page, my intention is to wait for #1640 to be merged, rebase on it, and then address the rest of your new review (thanks!). |
What do you think about the following, on top of #1640.
|
It is used, to represent the sourcemap of the linker output (in Link_js). |
#1640 has been merged, I'll let you rebase this one |
d7ef408
to
b78e277
Compare
Done |
I'm not very happy with the callback based approach used on Maybe we could move the handling/parsing of Sourcemap index into a separate PR to remove some noise in here. |
1d6cda1
to
f02c31f
Compare
Regarding the representations of edits. We currently have per line instructions. Have you considered using a different approach (closer to what's done on master with |
I considered it, but at the time discarded it as early optimisation. Now that the main source of slowdown as been eliminated, it might be worth trying. |
Actually, what I had considered was to have the edits represented as a list of “copy / delete n lines” rather than a long list of “copy / delete 1 line”. What you suggest would make |
Can we maybe revisit this approach. Maybe we could teach link_js to copy blocks of lines that do not mess up with sourcemap ? If we really want to drop comments, we could emit an empty line instead. We would probably need to emit Index map when compiling cma files so that we have one sourcemap per unit and we can easily drop dead units when linking. |
I've opened #1715 instead. It removes the need to change encoded mappings. |
Closing in favor of #1715 |
This improves the efficiency of sourcemap processing, chiefly during linking, but also in serializing and deserializing sourcemaps.
Currently, when linking with source maps enabled, js_of_ocaml will decode the source maps for each input file completely into an in-memory explicit mapping, then merge them, then re-encode the merged sourcemap. The merging algorithm involves superlinear sorting operations. However, the format of sourcemaps allows to avoid sorting for the concatenation of generated files.
In addition, all operations performed by linking (concatenation of files, removal and addition of lines) can be performed directly on the encoded form, which further avoids a full parsing to an in-memory representation.
When compiling js_of_ocaml with itself, the final linking step is accelerated by a speedup of about 2.3x with OCaml 5.2.0+fp:
fix #1446