Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy cache provider initialization [SPR-17646] #22175

Closed
spring-projects-issues opened this issue Jan 8, 2019 · 4 comments
Closed

Lazy cache provider initialization [SPR-17646] #22175

spring-projects-issues opened this issue Jan 8, 2019 · 4 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 8, 2019

Dave Syer opened SPR-17646 and commented

Several opportunities:

  • Pointcut processing is expensive, and involves reflecting on all methods of all beans. Clearly this doesn't scale well and could be indexed away. Could also be used with @Transactional (and @Secured etc.).
  • The cache provider (e.g. EhCache) has expensive internal initialization. This could perhaps be deferred until the cache is actually used.
  • Some other stuff in Spring Boot might help (condition evaluation and import selection)

Some analysis and benchmarks here: spring-attic/spring-init#5


Affects: 5.1.3

Reference URL: spring-attic/spring-init#5

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

The cache provider (e.g. EhCache) has expensive internal initialization. This could perhaps be deferred until the cache is actually used.

Just a note that several things may go wrong (configuration file not found, configuration invalid, network topology that has to be validated on startup) so whatever we do here should be opt-in. It would be nice though if we wouldn't have to do that for every single component that we optimize this way

@snicoll
Copy link
Member

snicoll commented Feb 1, 2019

Some additional data point here https://github.com/scratches/spring-cache-bench

@jhoeller
Copy link
Contributor

jhoeller commented Mar 12, 2019

For a start, #22420 covers the pointcut processing part: We are not traversing classes now if they are known to not declare the desired annotation type. This is implemented for our async, caching, and transaction annotations, ignoring java* classes by default but also participating in the single unified hook (AnnotationUtils.isCandidateClass) which we have for our upcoming indexer integration.

@jhoeller jhoeller changed the title Optimizations for @Cacheable methods [SPR-17646] Lazy cache provider initialization [SPR-17646] Mar 12, 2019
@jhoeller jhoeller modified the milestones: 5.2 M1, 5.2 M2 Mar 12, 2019
@jhoeller jhoeller removed their assignment Mar 27, 2019
@jhoeller jhoeller modified the milestones: 5.2 M2, 5.x Backlog Mar 27, 2019
@jhoeller jhoeller modified the milestones: 6.x Backlog, 6.1.x Jul 13, 2023
@jhoeller
Copy link
Contributor

On review, I'm not really seeing much potential in asynchronous cache provider bootstrapping. Caffeine starts very quickly, not worth doing anything asynchronously. And cache preloading is usually done through early triggering of certain Cacheable methods (e.g. on ContextRefreshedEvent), not through the cache provider itself, even with EhCache these days.

From that perspective, I'll close this ticket in its provider initialization variant. Any further improvements in annotation discovery won't be specific to caching annotations and are therefore better off in a different ticket.

@jhoeller jhoeller removed this from the 6.1.x milestone Aug 17, 2023
@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants