Improve trim speed during XML parsing. #1216
Merged
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.
Issue with parsing large XML responses
I recently noticed an issue with slow parsing of large (1-2mb+) responses.
I narrowed the issue down to the trim(text) method in wdsl/index.ts
This uses regex to remove whitespace characters at the start and end of a string.
This has performance implications when the string is very long, as I believe the trimRight regex needs to scan the entire content before reaching the end and then backtrack.
This issue was so bad it was causing requests to timeout after (10+ minutes).
Solution
I couldn't see any other tests testing the whitespace removal, so I added some.
I validated that it was extremely slow before the change (I gave up waiting after around 5 minutes).
I validated that after the change it was fast (~10ms).
And that the expected output is the same.