node-soap icon indicating copy to clipboard operation
node-soap copied to clipboard

Improve trim speed during XML parsing.

Open shellicar opened this issue 1 year ago • 2 comments

  • 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 avatar Mar 28 '23 03:03 shellicar

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

frebos88 avatar May 05 '23 12:05 frebos88

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.

shellicar avatar Sep 13 '23 06:09 shellicar

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

w666 avatar Apr 18 '24 08:04 w666