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

Improve trim speed during XML parsing. #1216

Merged
merged 1 commit into from Apr 18, 2024
Merged

Conversation

shellicar
Copy link
Contributor

  • Use native string.trim instead of regex replace for performance.
  • Add tests surrounding trim function used in wsdl parsing.

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.

@shellicar shellicar marked this pull request as ready for review March 28, 2023 03:18
Use native string.trim instead of regex replace for performance.

remove log line.
fix quotes in tests.
Copy link

@el-noppo el-noppo left a comment

Choose a reason for hiding this comment

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

LGTM

@frebos88
Copy link

frebos88 commented May 5, 2023

Tested the PR out and also saw a huge improvement in performance. 👌

@shellicar
Copy link
Contributor Author

Just wondering if this project is being maintained anymore?
I don't see any activity from the listed maintainers.

Another PR that seems quite important and supported isn't merged either (another issue I just ran into which brought me back here) - #1212

I ended up just forking the project and hosting it on my own package feed, but I figured there would have been some activity in the past few months.

@w666
Copy link
Collaborator

w666 commented Apr 18, 2024

Good one, thanks for submitting it, I will include in the next release.

@w666 w666 merged commit 690ae8c into vpulim:master Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants