Skip to content

perf(codemining): batch and cache the jump code mining labels - #389

Merged
RoiSoleil merged 1 commit into
masterfrom
fix/codemining-performance
Sep 24, 2026
Merged

RoiSoleil merged 1 commit into
masterfrom
fix/codemining-performance

Conversation

@RoiSoleil

Copy link
Copy Markdown
Contributor

Problem

With the "Jump to test method" code mining enabled, every code mining refresh (ie. every pause while typing) ran JDT index searches per method of the file:

per refresh (M methods in the file)
CorrespondingTypeSearcher (search engine) 2 per method + 1 per type (a new TypeFacade - and thus a new search - was created per mining)
MethodTestCallerFinder (call hierarchy) 1 per method
total for a 20-method class ≈ 41 index searches + 20 call hierarchy searches

Fix

  • new org.moreunit.codemining.JumpLabelComputer: the labels of all the minings of a compilation unit are computed in one batch, shared by the minings of the refresh → one single search for the corresponding test cases / classes under test (result cached by the TypeFacade);
  • the expensive search "by call" (call hierarchy) only runs for the methods for which no test method was found "by name";
  • the labels are cached: a label only depends on the element names and on the content of the corresponding files, not on the code being typed. The cache is invalidated when the structure of the compilation unit changes (added / removed / renamed element) or when one of the corresponding files changes (30 s safety net otherwise, eg. to notice a newly created test case).

Typical case (typing inside a method body): 0 search. After a structural change: 1 search + at most 1 call hierarchy search per untested method, instead of 3 searches per method at every refresh.

Behaviour is unchanged: the labels ("Jump to test method", "Jump to tested class", ...) are strictly the same - the 6 existing JumpCodeMiningTest scenarios pass unchanged.

Note: TestAnnotationMode.BY_CALL_AND_BY_NAME.getMethodSearchMode() returns a constant and does not read the preferences; this semantic is preserved on purpose. Making the labels honour the "test method search" preferences (which would let users disable the call hierarchy searches entirely) could be a follow-up.

Tests

  • 8 new unit tests (org.moreunit.codemining.JumpLabelComputerTest): labels for methods and types, from a class under test and from a test case; one single computation for all the elements of a file; no recomputation while the structure is unchanged (the typing case); recomputation when the structure changes, when the corresponding test case changes (eg. testFoo() just written in the test file) and when the cache expires.
  • existing tests unchanged and green (incl. the 6 JumpCodeMiningTest scenarios); full unit test run: 2029 tests, 0 failure.

Note: a small conflict on JumpCodeMining.java is expected with #388 (which refactors its jump action); trivial to rebase once either one is merged.

Resolving the "Jump to test/tested ..." code minings ran one JDT search per method and per refresh (2 index searches + 1 call hierarchy search for each method of the file), ie. dozens of searches at every pause while typing.

The labels of a compilation unit are now computed in one batch (one single search for the corresponding test cases / classes under test), the call hierarchy search only runs for the methods without test method found by name, and the labels are cached until the structure of the compilation unit or the content of the corresponding files changes (30s safety net). Typing in a method body now costs no search at all.

The computed labels are strictly unchanged.
@RoiSoleil
RoiSoleil merged commit 2c03d61 into master Sep 24, 2026
6 checks passed
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.

1 participant