Repository navigation
Optimize xFilter function for better performance - #4
Open
tonygermano wants to merge 1 commit into
Open
tonygermano wants to merge 1 commit into
tonygermano wants to merge 1 commit into
Conversation
Open Integration Engine Discord user `@Anibal` reported slowness issues when working with very large lists, e.g., filtering HL7 messages with several thousand OBX segments. One thing that was already known to me is that where `list` is an `XMLList` and `node` is an `XML` object, performing `list += node` will assign a new `XMLList` to `list`, which is a shallow copy of the original `list` with `node` appended to the end. Assigning `list[index] = node` where `index` is greater than or equal to the length of `list` will append to the list without copying it first. A caveat to this is that when all elements of an `XMLList` share the same `parent`, assignments in this manner will not only update `list`, but will also attempt to update the parent's child list. To get around this, the would-be first element of the returned list is remembered, and an empty XML object with no parent is inserted into the list in its place. The remainder of the list is built as normal, and at the end, the first element in the list is replaced with the reserved object. Through benchmarking shared in the discord chat, two additional optimizations were found. First, it is much faster to iterate over an XMLList using a `for each..in` loop than it is to use a normal `for` loop and access the list by index. Second, `list.length()` is much slower than expected, so the function scoped `match_count` is used to track the current length instead. Signed-off-by: Tony Germano <tony@germano.name>
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.
Open Integration Engine Discord user
@Anibalreported slowness issues when working with very large lists, e.g., filtering HL7 messages with several thousand OBX segments.One thing that was already known to me is that where
listis anXMLListandnodeis anXMLobject, performinglist += nodewill assign a newXMLListtolist, which is a shallow copy of the originallistwithnodeappended to the end. Assigninglist[index] = nodewhereindexis greater than or equal to the length oflistwill append to the list without copying it first.A caveat to this is that when all elements of an
XMLListshare the sameparent, assignments in this manner will not only updatelist, but will also attempt to update the parent's child list. To get around this, the would-be first element of the returned list is remembered, and an empty XML object with no parent is inserted into the list in its place. The remainder of the list is built as normal, and at the end, the first element in the list is replaced with the reserved object.Through benchmarking shared in the discord chat, two additional optimizations were found. First, it is much faster to iterate over an XMLList using a
for each..inloop than it is to use a normalforloop and access the list by index. Second,list.length()is much slower than expected, so the function scopedmatch_countis used to track the current length instead.