Skip to content

[MINDEXER-190] Avoid using String#split in hot code if possible - #317

Merged
cstamas merged 1 commit into
apache:masterfrom
mbien:avoid-split
Jun 13, 2023
Merged

cstamas merged 1 commit into
apache:masterfrom
mbien:avoid-split

Conversation

@mbien

@mbien mbien commented May 24, 2023 •

Copy link
Copy Markdown
Member
  • 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 (i6700k)

https://issues.apache.org/jira/browse/MINDEXER-190


indexer-split
indexer-no-split

 - 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
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;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cstamas changed the title Avoid using String#split in hot code if possible [MINDEXER-190] Avoid using String#split in hot code if possible Jun 13, 2023
@cstamas
cstamas merged commit 052c8cd into apache:master Jun 13, 2023
@jira-importer

Copy link
Copy Markdown

Resolve #548

1 similar comment
@jira-importer

Copy link
Copy Markdown

Resolve #548

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants