-
Notifications
You must be signed in to change notification settings - Fork 7
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
Rewrite uses search for performance, simplicity & correctness #509
Conversation
Also, there is a failure case within the current usage search around instanceof patterns. This is valid Java code, in which Object o = "Hello";
if (!(o instanceof String i)) {
throw new IllegalArgumentException();
}
System.out.println(i); The pattern variable |
Mine is just a new api, so we don't have like 20 different methods in |
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.
autograder-core/src/main/java/de/firemage/autograder/core/Uses.java
Outdated
Show resolved
Hide resolved
autograder-core/src/main/java/de/firemage/autograder/core/Uses.java
Outdated
Show resolved
Hide resolved
autograder-core/src/main/java/de/firemage/autograder/core/Uses.java
Outdated
Show resolved
Hide resolved
The implementation now works in all cases (i.e. passes all existing tests and some more, and generates the same problems on the A1 task as the main branch, aside from a bug on main). It's also a lot faster compared to main and the scope-limiting implemented in #503: Caching Uses:
Scope-Limiting:
Baseline on main:
Looking at the profiler, the checks take now less than 25% (1.2s) of the total runtime (5.3s), with the remaining large chunks being Spoon's model building (0.9s), PMD (1s), javac (0.9s), and Lingua (0.3s), which is disabled in practice anyway: The API is in no way finished, and I'm very unhappy with the current split of the model-related functionality into SpoonUtil, CodeModel, and now Uses/MethodHierarchy. It's especially inconvenient that the CodeModel has to be passed around everywhere where Uses may be needed. I've implemented a shortcut by caching the CodeModel inside the root CtPackage's metadata, but that feels hacky and may break sometime down the line. |
I did some profiling for the A1 test and found that the currently slowest check by far is the UnusedCodeElementCheck (and the UseDifferentVisiblityCheck, which also searches for code element uses). On my machine (i7-12700K) it looks like this:
With a profiler attached, the entire analysis takes about 17.5s, of which the UnusedCodeElementCheck takes ~7s, and the UseDifferentVisiblityCheck takes another 2.5s. For reference, the next slowest checks are the ConstantNamingAndQualifierCheck (0.84s), ReassignedParameterCheck (0.78s), and the UnusedImportCheck (0.58s). Model building takes only about 1s, which is faster than the compilation step! (probably due to laziness within Spoon)
Anyway, we should improve the performance of the usage search. The current implementation sweeps across the entire model for each code element that we want usage information for, which leads to a runtime of something like O(n²). The goal of this PR is to rewrite usage search with a single pass over the model and a caching strategy for different checks.