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

Slow CacheManager::getDriverList() #920

Open
MaximilianKresse opened this issue Oct 24, 2024 · 2 comments
Open

Slow CacheManager::getDriverList() #920

MaximilianKresse opened this issue Oct 24, 2024 · 2 comments
Assignees

Comments

@MaximilianKresse
Copy link
Contributor

MaximilianKresse commented Oct 24, 2024

What type of issue is this?

Other (Please Specify)

Operating system + version

Ubuntu 22.04

PHP version

8.2.24

Connector/Database version (if applicable)

No response

Phpfastcache version

9.2.0 ✅

Describe the issue you're facing

I'm currently trying to improve the speed of our controller and stumbled over something unexpected. We're currently adding a custom driver to PhpFastCache (with CacheManager::addCoreDriverOverride) and this calls internally CacheManager::getDriverList().

The method "CacheManager::getDriverList()" currently needs ~60ms on our development server. Yes this harddrive on this server is pretty slow - but why does this method work like this at all - in a library which you only want to use if you want to improve your speed.

Currently the CacheManager::getDriverList() method walks recursively over all files in the Drivers directory and then loads ALL php files in these completly into the memory and tokenizes them. Just to generate a list of classes which are always the same (at least if you don't change driver directory). This logic is probably a relict of the old way extension where added - but as far as I see this is no longer the case.

Can we please fix this?

Currently I see two ways to simply fix this:

  1. Replace this logic in getDriverList() by a simple hardcoded list of drivers.
  2. Add an option to insert the list from outside - something like CacheManager::setDriverList()
@Geolim4
Copy link
Member

Geolim4 commented Oct 24, 2024

Hello,

Replace this logic in getDriverList() by a simple hardcoded list of drivers.

This method was created because, in its old days, from one version to another, before extensions mechanism, the driver list could have changed periodically due to incompatibility or deprecations.
So I decided to discover it automatically using a former Symfony Component (ClassLoader) that I embedded into the core.

Add an option to insert the list from outside - something like CacheManager::setDriverList()

It is internally set and not meant to be set from the outside.

You right, I need to rework this method, either to harcode the driver list (but I'm not a fan) or find a better efficient way to discover core drivers.

I'll take a look this weekend.
In the meantime, you can extend the CacheManager to rewrite ::getDriversList().

@Geolim4
Copy link
Member

Geolim4 commented Nov 27, 2024

Not forgetting you, just being busy...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants