PHPSocialNetwork / phpfastcache

A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
https://www.phpfastcache.com
MIT License
2.38k stars 451 forks source link

Slow CacheManager::getDriverList() #920

Open MaximilianKresse opened 3 days ago

MaximilianKresse commented 3 days ago

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 commented 3 days ago

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().