Skip to content

Refactoring: Improve listClassPathHints() performance#8948

Merged
mbien merged 1 commit intoapache:masterfrom
mbien:cp-hint-init-performance
Oct 25, 2025
Merged

Refactoring: Improve listClassPathHints() performance#8948
mbien merged 1 commit intoapache:masterfrom
mbien:cp-hint-init-performance

Conversation

@mbien
Copy link
Member

@mbien mbien commented Oct 22, 2025

The binary class path Set has the tendency to have duplicated roots. The added deduplication pass ensures that findSourceRoots2 isn't called more often than necessary.

This can significantly improve the performance during code inspect and transform actions, esp when many projects are open.

relative time spent in listClassPathHints() during inspect/transform dialog open.

before:
image

after:
image

benchmark was a project wide code inspection run with all 856 NetBeans modules open.
listClassPathHints() execution time in ms

before:

  17375 cold
   6177 warm

after:

  3648 cold
  1299 warm

the number of entries was reduced from 154997 to 1258 in that use case.

The binary class path Set has the tendency to have duplicated roots.
The added deduplication pass ensures that findSourceRoots2 isn't called
more often than necessary.

This can significantly improve the performance during code inspect and
transform actions, esp when many projects are open.
@mbien mbien added this to the NB29 milestone Oct 22, 2025
@mbien mbien requested a review from lahodaj October 22, 2025 20:40
@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) performance hints labels Oct 22, 2025
Copy link
Contributor

@eirikbakke eirikbakke left a comment

Choose a reason for hiding this comment

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

Seems like a simple change, gathering up FileObject instances in a Set to deduplicate before iterating over them. Plus some cosmetic code cleanup (renamed variables etc.). Thanks for this!

Set<FileObject> roots = new HashSet<>();

// deduplicate before running queries
Set<FileObject> unique = new HashSet<>(128);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does iteration order matter for these sets? I always tend to use LinkedHashSet, to avoid items being randomized.

Copy link
Member Author

Choose a reason for hiding this comment

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

it shouldn't matter in this particular case, the method input already was a regular HashSet. Since its an internal utility class we could change this based on usage I think.

Copy link
Contributor

@lahodaj lahodaj left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks! I don't think the order is particularly important, the input ClassPaths are in a set anyways.

@mbien
Copy link
Member Author

mbien commented Oct 25, 2025

thanks for the reviews! merging some smaller PRs like this one here.

@mbien mbien merged commit d753c90 into apache:master Oct 25, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants