Skip to content

Memoize the name lookups of JavaParserUtil.resolveTypeName - #8182

Merged
mernst merged 1 commit into
masterfrom
resolve-type-name-memoize
Sep 17, 2026
Merged

mernst merged 1 commit into
masterfrom
resolve-type-name-memoize

Conversation

@mernst

@mernst mernst commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Resolving one type name looks up many candidate names -- one per enclosing type declaration, one per import, one per on-demand import, one in the same package, one in java.lang, and one for the name as a fully-qualified name. Most of those names name no type, and a client that resolves many names looks up the same names repeatedly.

Add an overload of resolveTypeName that takes a cache, and route every lookup through it. The existing one-argument overload is unchanged from a caller's point of view; it allocates a cache that lives for the one call.

This is a performance change only: it changes no result, and no test output changes. A cache must not be reused across annotation processing rounds or across Elements instances, because a name that names no type in one round might name a generated type in a later round; the Javadoc says so.

🤖 Generated with Claude Code

Resolving one type name looks up many candidate names -- one per enclosing
type declaration, one per import, one per on-demand import, one in the same
package, one in `java.lang`, and one for the name as a fully-qualified name.
Most of those names name no type, and a client that resolves many names looks
up the same names over and over.

Add an overload of `resolveTypeName` that takes a cache, and route every
lookup through it, so that a client that resolves many names pays for each
distinct name only once.  The cache records a lookup that finds no type, which
is the common case.  The existing one-argument overload is unchanged from a
caller's point of view; it allocates a cache that lives for the one call.

This is a performance change; it does not change any result.  A cache must not
be reused across annotation processing rounds or across `Elements` instances,
because a name that names no type in one round might name a generated type in
a later round; the Javadoc says so.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 15fb69a6-cee3-45d9-b5c7-6d290d73480e

📥 Commits

Reviewing files that changed from the base of the PR and between e405420 and 2263d3a.

📒 Files selected for processing (1)
  • framework/src/main/java/org/checkerframework/framework/util/JavaParserUtil.java

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

JavaParserUtil now memoizes type element lookups during type-name resolution. The existing resolver delegates to a new overload that accepts a shared cache. Enclosing-type, import, package, fallback, and inherited member-type lookups use the cache through a private helper. Cached null results are also reused.

Priority: ⬇️ Low

Change: Refactor

Merge Risk: ⚪ Minimal · up to 2263d

The memoization change retains the existing resolver behavior while documenting safe cache scope. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch resolve-type-name-memoize

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.

@mernst
mernst requested a review from smillst September 16, 2026 19:06
@mernst
mernst merged commit 6630f01 into master Sep 17, 2026
57 checks passed
@mernst
mernst deleted the resolve-type-name-memoize branch September 17, 2026 01:53
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