Skip to content

Consider caching interface-derived BeanInfo instances in CachedIntrospectionResults [SPR-16568] #21110

Closed

Description

@spring-projects-issues

Andy Wilkinson opened SPR-16568 and commented

CachedIntrospectionResults currently caches the results for the Class passed to forClass(Class), but not for the Class passed to getBeanInfo(Class, boolean). If multiple classes passed to forClass(Class) implement the same interface, multiple BeanInfo instances will be created for that interface. For example, in a small Spring Boot sample application 27 BeanInfo instances are created for org.springframework.core.Ordered.

This doesn't appear to have too much impact in a small application, but as an application grows and there are more classes implementing the same interfaces, I wonder if caching would become increasingly beneficial?


Affects: 5.0.4

Issue Links:

Referenced from: commits a02aafe

Activity

  1. spring-projects-issues commented on Mar 8, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Since Introspector.getBeanInfo is supposed to use a cache internally, it seems like a net-negative for us to call it with IGNORE_ALL_BEANINFO for interfaces since this seems to bypass the cache... We could just call the standard variant, at the expense of the introspector looking for a BeanInfo class on the classpath then but caching the outcome at least. This would avoid the need for locally caching the interface-derived BeanInfo instances ourselves.

  2. spring-projects-issues commented on Mar 8, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    This seems to be the case indeed, so I'll go with that solution. It doesn't hurt for the interface lookup to consider BeanInfo classes (that simply won't ever exist); we're simply trading off an extra classpath lookup once per interface over rebuilding the BeanInfo instances for every occurrence of the interface on an introspected bean class. Also, the general spring.beaninfo.ignore=true flag suppresses that extra classpath lookup for interfaces anyway.

  3. added
    type: enhancement
    in: core
    on Jan 11, 2019
  4. added this to the 5.0.5 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions