Performance improvement, typically 25%, by splitting internal 'is' function #204
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.
Hello, at my current place of work we’ve been processing relatively large XML documents with
expat
but recently started trialling the use of the object-buildingxml2js
, which depends upon this module.Performance was of concern, so I carried out some V8 profiling and discovered a few hot spots:
This module currently has an internal
is
function that accepts either a RegExp or an Object. Much of the time is spent determining what data type has been passed to it by callingObject.prototype.toString
.Luckily the type is already known at all the call sites for this function, so this PR splits the
is
function into an Object version and a RegExp version. The RegExp version also uses the short-circuitingregex.test
rather than a fullregex.match
.Profiling with the changes in this PR reveals the hot spots are gone:
Performance testing with real world XML of various orders of magnitude with a Node v6 runtime suggests performance gains are in the 25-40% region, possibly slightly more for even larger documents or longer running processes.
The contribution guide asks for tests but I'm unsure of the best way to further test this change beyond the existing and already-extensive unit test suite; guidance welcome here.
Thank you for continuing to maintain this highly-depended upon module.