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

[Perf][RFC] make the autoload_static $classMap keys hashes #11595

Open
dkarlovi opened this issue Aug 24, 2023 · 3 comments
Open

[Perf][RFC] make the autoload_static $classMap keys hashes #11595

dkarlovi opened this issue Aug 24, 2023 · 3 comments

Comments

@dkarlovi
Copy link

My composer.json:

https://github.com/pimcore/demo/blob/11.x/composer.json

With some larger monolithic apps like Pimcore which include a lot of deps, autoload_static.php can grow so big it starts showing up on memory profiles.

For rough idea, on one of my Pimcore projects, it's 5.5MB and has 36k lines. On a rather simple Symfony project, it's 200KB and has 2K lines.

It seems an optimization might be possible where the FQCN in $classMap is replaced by its hash, just like $files. Since FQCN is in many cases longer than a hash (sometimes much longer), this might have a beneficial impact both on the on-disk size, but also in-memory size. I know opcache will dedup strings, but the string still needs to be kept in memory once, this will make that string shorter and should in theory improve performance.

Thoughts?

@stof
Copy link
Contributor

stof commented Aug 24, 2023

this would force the ClassLoader to perform a hash computation for each loaded class, which will have an impact on performance.

Keys in the files list are used as a deduplication key, but the ClassLoader only loops over the variable. the classMap is used a map.

@dkarlovi
Copy link
Author

perform a hash computation for each loaded class, which will have an impact on performance.

Correct, this is the tradeoff suggested. This might be an opt-in option if you know your classmap is gigantic so you get to pick if you want to pay with CPU or memory.

@Seldaek
Copy link
Member

Seldaek commented Aug 30, 2023

If you wanna trade runtime for memory, I'd suggest maybe not optimizing the classmap at all so you have a smaller classmap? But then it's rather io cost than cpu..

So yeah probably hashing would still be faster, but this seems like a very niche case to me. With opcache the classmap is only present once in memory and shared between fpm workers AFAIK, so that really shouldn't be a huge impact.

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

No branches or pull requests

3 participants