-
-
Notifications
You must be signed in to change notification settings - Fork 324
Refactor the cache to cache all definitions at once? #477
Description
I think the main way to achieve a huge performance improvement would be to change the way definitions are cached.
Currently each definition is cached under its own key. So on each request, each service entry means one cache call. That's why APCu is recommended and Redis is not (because that would mean hundred of cache calls through the network).
I think the whole cache system can be refactored into something better:
- currently we cannot cache all definitions under one cache entry because:
- we don't know all the possible container entries because of autowiring
- if we had one cache entry and updated it each time we cache a new definition, we would run into race conditions
- the cache cannot be warmed up
I think we could have a middle ground:
- the warmup could take all definitions explicitly defined in the config, resolve them and cache them
- when resolving an entry, the container will then hit the cache for entries in the config, and for new entries that are not in the config (autowiring/annotations) those can get a separate cache key
That means that we could save a good amount of cache queries. And that way also, users that want to optimize for maximum performances could add foo::class => autowire() configuration for each class (just to benefit from the warmup/grouped cache).
One thing that will not be easy to deal with is wildcard :) But in a first version maybe those can be ignored (performances will not be worse anyway).