-
Notifications
You must be signed in to change notification settings - Fork 227
Performance: Cache method calls in loops and optimize string concaten… #3515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance: Cache method calls in loops and optimize string concaten… #3515
Conversation
Test Results 3 018 files 3 018 suites 2h 16m 45s ⏱️ Results for commit 17b524d. ♻️ This comment has been updated with latest results. |
ea72901 to
3b853bf
Compare
| */ | ||
| public int indexOf(String id) { | ||
| for (int i = 0; i < contributions.size(); i++) { | ||
| int size = contributions.size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this something the compilier anyway optimizes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not likely, the size could change in the loop. I personally prefer this style:
for (int i = 0, size = contributions.size(); i < size; i++) {
Assuming the intent is not to deal with the size changing in the loop.
| - currentTriggerSequence.format().length(); | ||
| int bestLength = bestTriggerSequence.format().length(); | ||
| int currentLength = currentTriggerSequence.format().length(); | ||
| compareTo = bestLength - currentLength; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should this be faster? the number of method calls does not change.
|
Thanks for the early feedback but I would prefer if draft reviews are not pro-actively reviewd. For example, the currentTriggerSequence.format().length(); change is obviously non-sense, I only did not yet find the time to update the PR. So better spend time in reviewing non-draft PR to avoid spending time on something that is not yet ready to be reviewed. |
7d5510c to
2ddd35f
Compare
|
These changes won't be noticeable to end users. They're technically correct optimizations, but the performance gain is likely unmeasurable. The main value is in code quality and avoiding unnecessary allocations, not in user-perceivable performance improvement. |
We have
just as you asked here #3517 I would suggest to enable such cleanups on a more general scope. |
I tried this once in the past and it create tons of silly changes. I don't think this is one of the clean-up I would like to activate. The changes here are more dedicated. |
2ddd35f to
856c71a
Compare
|
Please put suggestions for new clean-up into this issue: #3517 |
Pick one example, report it to JDT and it can be fixed (maybe even with the help of the AI). @jjohnstn did a great job lately, but without using the cleanups and reporting issues things will never improve.
Dedicated to what? You said its all likely not noticeable by the user so claim they improve "performance" is maybe bit to big thing to claim. But if the real goal is as claimed here
then it would be much more valuable to:
|
The conversion was not wrong but for places which not performance relevant like debug output and increased the code complexity IMHO. Like always you are free to investigate yourself (to which you usually reply you do not have the time for that which is valid and also the reason why I do not plan to work on this as I also do not have the time for this). |
This is a valid concern that could probably be addressed
You asked for where you are could have used cleanups and I just gave you examples, apart from that I always have incrementally enabled cleanups and investigate what are useful and reporting bugs: there is even one (open) enhancement request: So yes everyone is busy but especially then we should not have 100'd of fragmented micro optimizations. |
9a47563 to
b795d93
Compare
|
Trying to address the flaky Mac test here: #3532 |
b795d93 to
59bb59e
Compare
1a7a7d8 to
e8a2f85
Compare
concatenation Apply low-risk performance optimizations across multiple bundles: Loop optimizations - cache method results: - StyledString: Cache otherRuns.size() before loop - ContributionManager: Cache contributions.size() in indexOf() and duplicate removal - ContentProposalAdapter: Cache autoActivateString.length() in loop - DialogSettings: Cache s.length() before character iteration - MenuManagerShowProcessor: Cache menuModel.getChildren() to avoid repeated calls - WorkbenchPage: Cache getChildren() results to avoid expensive repeated calls String concatenation optimizations: - WizardsRegistryReader: Use StringBuilder for path construction in loop - NewContentTypeDialog: Use StringBuilder for name generation in while loop Repeated expensive calls: - BindingManager: Cache format().length() results in comparison - MenuManagerShowProcessor: Cache getChildren() in loop condition and body All changes are non-API breaking and maintain identical behavior while reducing unnecessary object allocations and method calls.
e8a2f85 to
17b524d
Compare



Apply low-risk performance optimizations across multiple bundles.
After review, this PR contains only the legitimate performance improvements:
Repeated method call caching:
String concatenation optimizations:
All changes are non-API breaking and maintain identical behavior while reducing unnecessary object allocations and method calls.
Note: Changes that provided no actual benefit (caching simple field accesses like List.size(), String.length(), or unnecessary variable extractions) have been removed.