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
Creating AnalysisResult
objects is expensive due to IdentityHashMap
copies
#5172
Comments
This sounds good to me. Thanks for the suggestion. To avoid making empty |
My plan for fixing this was as follows:
I think this works at a high level, but it's ugly to change the declared type of the fields to https://errorprone.info/bugpattern/IdentityHashMapUsage I think what we may want here is a method I was hoping to get feedback on this proposal, in case someone sees a simpler solution. Thanks! |
This sounds good to me. It sounds like you don't think the creation of the empty A quick search didn't turn up anyone else who had implemented something like |
Yeah, in the profiles, the main issue was calls to
I didn't find anything either. The solution is still a bit ugly, as we will have to subclass |
I've been looking into profiling NullAway's dataflow analysis more carefully with a micro-benchmark to find unnecessary overheads. I created the following synthetic benchmark (may be useful for Nullness Checker as well), and I profiled repeatedly running NullAway on the benchmark in a loop:
https://github.com/msridhar/NullAway/blob/manu-dflow-bench-test/nullaway/src/test/resources/com/uber/nullaway/testdata/DFlowBench.java
I observed that on this benchmark, nearly half the execution time is spent creating
IdentityHashMap
objects, as part of constructing the finalAnalysisResult
after dataflow analysis completes. There are severalIdentityHashMap
fields insideAnalysisResult
. I see that the contents of the maps get mutated inside theAnalysisResult.combine()
method, but not elsewhere that I can see (it's possible subclasses are allowed to mutate the contents). Depending on the intended invariants, I am wondering if we could rewrite this code to lazily create copies ofIdentityHashMap
s (like only when combining results) rather than doing it eagerly, maybe usingCollections.unmodifiableMap()
to catch any unintended mutation without copying entire maps. I'm happy to put up a PR if we can agree on an approach.The text was updated successfully, but these errors were encountered: