improve performance of XmlComplexContentImpl.arraySetterHelper#30
Closed
pjfanning wants to merge 1 commit intoapache:trunkfrom
Closed
improve performance of XmlComplexContentImpl.arraySetterHelper#30pjfanning wants to merge 1 commit intoapache:trunkfrom
pjfanning wants to merge 1 commit intoapache:trunkfrom
Conversation
Member
Author
|
JMH testing in https://github.com/pjfanning/poi-bench shows none of the expected performance benefit |
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.
When saving large XLSX files via POI,
arraySetterHelperiterates over N source elements and for each callsfind_element_user(QName, int i)with a monotonically increasingi. Sincefind_element_useralways rescans from_firstChild, this is O(n) per call — O(n²) total for N elements.https://issues.apache.org/jira/browse/XMLBEANS-438
Changes
commonSetterHelper/commonSetterHelper2: Pre-fetch all existing child elements once withfind_all_element_users(O(n)) before the loop, then use O(1) list indexing instead offind_element_user(name, i)on each iteration.arraySetterHelperfast-path inner loop: Replaces the per-iterationfind_element_user(name, j)call withexistingList.get(j - originalI - insertCount). AninsertCountcounter tracks in-loop insertions that shift the original elements rightward in the store, keeping the index arithmetic correct without re-scanning.arraySetterHelpergeneral-case final loop: Lazily builds afinalListafter the excess-removal pass, then usesfinalList.get(j)for existing positions instead offind_element_user(name, j).Before:
After:
Overall complexity for N-element array setter operations: O(n²) → O(n).