Repository navigation
Conversation
Collaborator
|
i had a dig through this as im not a huge fan of having to add a bunch of logic around "spilled strings". all we're talking about here is appending chunks rather than characters when we're dealing with large strings. so i wonder if this can be much simpler...
i tried this in a branch and it seems faster since we're not accumulating or joining arrays, and uses the same or less memory. once i clean the branch up a bit ill push it so you can take a look and tell me if you still think this approach is better |
Collaborator
|
Opened #1897 with Jame's solution; ended up working quite well. |
Collaborator
|
Thanks @auscaster! Merged the other PR instead, with you as a co-author for the tests that were adopted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The tokenizer builds attribute values and character tokens by appending one code point at a time (
value += ch,chars += ch). In V8 every+=leaves a rope node behind until the string is read, so a long run holds tens of bytes per character while it is being built. Real pages have long runs: an inlinedata:image in an attribute, or a large inline script.We hit this parsing a vendor page that embeds a 7.3 MB base64 PNG in an SVG
xlink:href. Parsing it held about 222 MB of heap for that one value, enough to exhaust a 384 MB worker.This keeps short runs as native strings, so the common path only adds a length check. A run that reaches 1,024 characters moves into a small list of pieces, and every 32 pieces are joined into one flat string. The value is settled when the next attribute starts or the tag is emitted, and a character token is settled when it is emitted. The tokens the tree builder receives are unchanged.
Measured against
master, built locally:masterAll existing tests pass (19,327). One test is added for long attribute values and character runs with character references at the spill boundary.