Skip to content

TypeToken#getRawType allocates a lot #7957

@kilink

Description

@kilink

Guava Version

33.4.8-jre

Description

TypeToken#getRawType is needlessly expensive for TypeToken instances where the runtime type is already a Class; it allocates an ImmutableSet builder, a TypeVisitor. Ideally for Class / ParameterizedType, no allocations would occur.

Example

TypeToken.of(Object.class).getRawType(); // ideally shouldn't allocate
new TypeToken<List<Object>>(){}.getRawType(); // ideally shouldn't allocate, or should allocate less

Expected Behavior

I would not expect getRawType to allocate so heavily for trivial TypeTokens.

Actual Behavior

Several GBs of allocations observed in a 3 minute profile from a production application, or 1% of allocations.

Packages

com.google.common.reflect

Platforms

No response

Checklist

  • I agree to follow the code of conduct.

  • I can reproduce the bug with the latest version of Guava available.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions