Repository navigation
[MINDEXER-190] Avoid using String#split in hot code if possible - #317
Merged
Merged
Conversation
- async-profiler showed two optimization opportunities in the index creation code - IndexDataReader can avoid some work by moving an if-check up - split can be replaced by indexOf + substring pairs - this reduces MT extraction time from ~328s to ~303s on my machine
mbien
commented
May 24, 2023
Comment on lines
-354
to
+362
| final String[] splitInfo = ArtifactInfo.FS_PATTERN.split(info); | ||
| if (splitInfo.length > 6) { | ||
| final String extension = splitInfo[6]; | ||
| final String uinfoString = uinfoField.stringValue(); | ||
| if (uinfoString.endsWith(ArtifactInfo.FS + ArtifactInfo.NA)) { | ||
| uinfoField.setStringValue(uinfoString + ArtifactInfo.FS + ArtifactInfo.nvl(extension)); | ||
| String uinfoString = uinfoField.stringValue(); | ||
| if (uinfoString.endsWith(ArtifactInfo.FS + ArtifactInfo.NA)) { | ||
| int elem = 0; | ||
| for (int i = -1; (i = info.indexOf(ArtifactInfo.FS, i + 1)) != -1; ) { | ||
| if (++elem == 6) { // extension is field 6 | ||
| String extension = info.substring(i + 1); | ||
| uinfoField.setStringValue(uinfoString + ArtifactInfo.FS + ArtifactInfo.nvl(extension)); | ||
| break; | ||
| } |
Member
Author
There was a problem hiding this comment.
if-check got moved before split is called to skip some work
I am sorry that the for-loop looks so ugly but the while didn't look any better unfortunately. This is essentially moving the window till it is at field 6, then the substring is extracted.
cstamas
approved these changes
May 26, 2023
This was referenced Jun 6, 2023
|
Resolve #548 |
1 similar comment
|
Resolve #548 |
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.
splitcan be replaced byindexOf+substringpairshttps://issues.apache.org/jira/browse/MINDEXER-190