Skip to content
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

Speed up template migrations #14679

Merged
merged 3 commits into from
Oct 16, 2024
Merged

Speed up template migrations #14679

merged 3 commits into from
Oct 16, 2024

Conversation

thecrypticace
Copy link
Contributor

This PR does two things:

  • Computes UTF-16 string positions in Rust rather than in JS — eliminating a significant number of traversals of the input string
  • Applies replacements to the content in ascending order so we only ever move forward through the source string — this lets v8 optimize string concatenation

@thecrypticace thecrypticace force-pushed the fix/v4-fast-template-slicing branch 2 times, most recently from 19ad87f to 098a804 Compare October 15, 2024 16:58
This makes sure that we’re always slicing the original string and not a changing string. This means that we can traverse the candidate replacements forward through the string rather than slicing and applying them in reverse order. A little extra bookkeeping is required but produces a decent speedup in v8.
Instead of using `string-byte-slice` which effectively scans through the entire string every time an index is computed.

We can instead scan through the content one time while computing utf-8 and utf-16 positions simultaneously allowing us to properly convert between the two. While we do still do a full string traversal it only happens once.
@thecrypticace thecrypticace force-pushed the fix/v4-fast-template-slicing branch from 098a804 to 374b076 Compare October 15, 2024 17:04
Copy link
Member

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow

@RobinMalfait RobinMalfait merged commit 92a43d6 into next Oct 16, 2024
1 check passed
@RobinMalfait RobinMalfait deleted the fix/v4-fast-template-slicing branch October 16, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants