Skip to content

Various optimizations#1358

Merged
msridhar merged 11 commits intomasterfrom
cache-hashcode
Dec 2, 2025
Merged

Various optimizations#1358
msridhar merged 11 commits intomasterfrom
cache-hashcode

Conversation

@msridhar
Copy link
Copy Markdown
Collaborator

@msridhar msridhar commented Nov 29, 2025

These were showing up in profiles. Note that one of the fixes requires updating our minimum supported Guava version to 31.1. This was released in February 2022, and mostly Guava is backward compatible these days, so hopefully it's fine for users.

Summary by CodeRabbit

  • Refactor

    • Added cached hash/identity values to reduce repeated recomputation.
    • Optimized nullness-store merging with faster merge and identity short-circuit.
    • Builder internals switched to immutable-building semantics.
    • Improved error-message construction formatting.
  • Chores

    • Bumped Guava dependency to a newer version.
    • Added Guava to the oldest-error-prone test classpath.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 29, 2025

Walkthrough

Adds cached hashCode fields and private computeHashCode() methods to AccessPath and FieldOrMethodCallElement, initializing cachedHashCode in constructors and returning it from hashCode(). Refactors NullnessStore.leastUpperBound for single-pass merging (iterating the smaller map), adds an identity fast-path in equals, and switches Builder to ImmutableMap.Builder, removing null-checks and using buildKeepingLast(). Updates an error message formatting in EnclosingEnvironmentNullness. Bumps Guava to 31.1-jre and adds Guava to oldest Error Prone test classpaths in related Gradle files.

Suggested reviewers

  • yuxincs
  • lazaroclapp

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Various optimizations' is vague and generic, using non-descriptive language that doesn't convey specific information about the changes. Consider a more specific title that highlights the primary optimization, such as 'Cache hashCode in AccessPath and FieldOrMethodCallElement' or 'Optimize hot path with cached hash codes'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cache-hashcode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.47%. Comparing base (2294177) to head (0b4c233).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1358      +/-   ##
============================================
+ Coverage     88.39%   88.47%   +0.07%     
- Complexity     2594     2602       +8     
============================================
  Files            98       98              
  Lines          8705     8727      +22     
  Branches       1732     1736       +4     
============================================
+ Hits           7695     7721      +26     
+ Misses          505      503       -2     
+ Partials        505      503       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f2343e and 8916b68.

📒 Files selected for processing (1)
  • nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.

Applied to files:

  • nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java
🔇 Additional comments (1)
nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java (1)

223-231: LGTM!

The reference equality fast-path is a standard and effective optimization for equals methods.

Comment thread nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java Outdated
Comment thread nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java Outdated
@msridhar msridhar changed the title Cache hash codes for a couple of classes Optimizations Nov 29, 2025
…e.java


var renaming

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java (2)

202-214: Please remove the commented-out legacy leastUpperBound implementation.

The old implementation is fully preserved in version control; keeping it commented out here adds noise to a performance-sensitive method and makes the current implementation harder to scan.

-    //    NullnessStore.Builder result = NullnessStore.empty().toBuilder();
-    //    for (AccessPath ap : intersection(contents.keySet(), other.contents.keySet())) {
-    //      Nullness apContents = contents.get(ap);
-    //      if (apContents == null) {
-    //        throw new RuntimeException("null contents for " + ap);
-    //      }
-    //      Nullness otherAPContents = other.contents.get(ap);
-    //      if (otherAPContents == null) {
-    //        throw new RuntimeException("null other contents for " + ap);
-    //      }
-    //      result.contents.put(ap, apContents.leastUpperBound(otherAPContents));
-    //    }
-    //    return result.build();

355-356: TODO about ImmutableMap.Builder is reasonable; consider tracking as a follow-up.

Leaving the TODO here is fine for this PR, but since this class is on hot paths, switching the builder to ImmutableMap.Builder (with explicit semantics for duplicate keys) seems worth tracking in a separate optimization issue.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8916b68 and 53951c7.

📒 Files selected for processing (1)
  • nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.

Applied to files:

  • nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java
🔇 Additional comments (1)
nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java (1)

224-226: this == o fast-path in equals is safe and appropriate.

Given NullnessStore is immutable, the reference-equality short-circuit is correct and avoids the map equality check in the common self-comparison case (e.g., in hash-based collections).

Comment thread nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStore.java Outdated
@msridhar msridhar changed the title Optimizations Various optimizations Dec 2, 2025
@msridhar msridhar requested a review from yuxincs December 2, 2025 20:59
@msridhar msridhar enabled auto-merge (squash) December 2, 2025 21:27
@msridhar msridhar merged commit effe83d into master Dec 2, 2025
11 checks passed
@msridhar msridhar deleted the cache-hashcode branch December 2, 2025 21:37
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.

2 participants