Repository navigation
perf: read text between tags in one slice and skip CRLF normalization when there is no CR - #918
Open
deadstrobe5 wants to merge 1 commit into
Open
deadstrobe5 wants to merge 1 commit into
deadstrobe5 wants to merge 1 commit into
Conversation
… when there is no CR
This branch has not been deployed
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.
Purpose / Goal
Text content costs much more than it should.
parseXmlappends text one character per loop iteration (textData += xmlData[i]), and before thatxmlData.replace(/\r\n?/g, ...)scans the whole input even when it has no\rat all. On documents with large text nodes (base64 payloads, prose, feeds) these two loops are most of the parse time.This PR copies each run of text up to the next
<with oneindexOfandsubstring, then moves the loop index to the end of the run. The string handed tosaveTextToParentTagis the same as before (same start, same end at the next<or the end of input), so trimming, entity decoding, value parsing and the callbacks see the same input. The CRLF replace now runs only when the input contains a\r; without one it was an identity replace, andcrlfPositionsstays empty as before.Same-process A/B on Node 24,
ignoreAttributes: false, median of 7 alternating rounds:The new spec checks long text with emoji and accents, mixed text around child tags, comments, entities and CDATA, with and without
preserveOrder, and passes on master too. A differential fuzz against master (random documents with entities, CDATA, comments, PIs, CR and CRLF,captureMetaData, 9 option sets, 54,000 comparisons, including reused parser instances) gave identical output, metadata and errors.Type