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

Use binary format for state set cache for better performance and OPcache exclusion #144

Merged
merged 4 commits into from
Jan 17, 2025

Conversation

Toflar
Copy link
Contributor

@Toflar Toflar commented Jan 16, 2025

I want to disable storing the state set in OPcache by default for the reasons described in the docs of this PR.

However, the current solution using ini_set('opcache.enable', '0'); won't work because this affects all other scripts loaded after the state_set.php as well. However, I couldn't find a way to disable OPcache for just one specific file while still dumping that file as pure PHP because that's still a lot faster than loading all the states from SQLite...

Any hints welcome 😊

Using pack() and unpack() was way faster in my tests than just a regular PHP array so let's drop OPcache support completely for better interoperability.

@Toflar Toflar added this to the 0.9 milestone Jan 16, 2025
@ausi
Copy link

ausi commented Jan 16, 2025

Did you try storing it in binary format using something like

$states = [1 => true, 7 => true, 123 => true];
file_put_contents(…, pack('N*', ...array_keys($states)));

And then loading it back in using unpack:

$data = unpack('N*', file_get_contents(…));
$states = array_combine($data, array_fill(0, \count($data), true));

Depending on alphabet size and index length you might need a larger or smaller integer. N is unsigned 32 bit.

@Toflar Toflar force-pushed the feature/adjust-opcache branch from 812872f to 92a9440 Compare January 17, 2025 09:30
@Toflar Toflar force-pushed the feature/adjust-opcache branch from 92a9440 to 38dab35 Compare January 17, 2025 09:30
@Toflar Toflar marked this pull request as ready for review January 17, 2025 09:30
@Toflar Toflar changed the title Disable OPcache by default Use binary format for state set cache for better performance and OPcache exclusion Jan 17, 2025
@Toflar
Copy link
Contributor Author

Toflar commented Jan 17, 2025

I thought about it but did not do any measurements because I thought this for sure will be slower than just a regular PHP array. But to my own surprise this was not the case but quite the opposite, it's actually way, way faster! 🤯
So I've dropped all OPcache stuff and what we're left with is a problem solved and better performance introduced 🤣 Nice!

@Toflar Toflar merged commit b1360df into develop Jan 17, 2025
18 checks passed
@Toflar Toflar deleted the feature/adjust-opcache branch January 17, 2025 09:46
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

Successfully merging this pull request may close these issues.

2 participants