Skip to content

Short-circuit TypeToken#equals for same instance comparison#8427

Closed
kilink wants to merge 1 commit into
google:masterfrom
kilink:type-token-equals
Closed

Short-circuit TypeToken#equals for same instance comparison#8427
kilink wants to merge 1 commit into
google:masterfrom
kilink:type-token-equals

Conversation

@kilink
Copy link
Copy Markdown
Contributor

@kilink kilink commented May 14, 2026

Avoid delegating to the runtime type's equals implementation in TypeToken#equals for identical instances of TypeTokens.

Depending on the implementation of Type, the equals method for runtimeType can be somewhat costly (e.g., triggering array cloning for ParameterizedType, etc). We actually have a scenario where cached TypeToken instances are often compared, and our equals implementation for ParameterizedType was less than ideal and showed up on some performance traces. I've fixed that as well, but TypeToken may as well avoid the call altogether if it can.

Avoid delegating to the runtime type's equals implementation in TypeToken#equals for
identical instances of TypeTokens.
@cpovirk cpovirk self-assigned this May 14, 2026
@cpovirk cpovirk added type=enhancement Make an existing feature better package=reflect P2 labels May 14, 2026
@kilink kilink deleted the type-token-equals branch May 14, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 package=reflect type=enhancement Make an existing feature better

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants