Repository navigation
perf: write runtime cache payloads as plain arrays when OPcache serves them - #174
Merged
Merged
Conversation
Cache files stored base64(gzcompress(serialize())) so large payloads did not become array literals that are expensive to parse. With OPcache that parse happens once per file version, while inflating and unserializing the compressed form runs on every include. A plain array file is compiled once into shared memory and each include returns the immutable array without parsing or copying it. export_payload() now writes the plain array when the writing process serves includes from OPcache shared memory (opcache.enable, plus opcache.enable_cli on the CLI, and not opcache.file_cache_only), and keeps the compressed form otherwise. The new blockstudio/cache/compress filter overrides the choice per scope, for example when WP-CLI without OPcache warms the cache for web workers that use it. The cache version moves to 7 so existing files are rewritten in the new format.
Contributor
|
Merged and released in Blockstudio 7.7.8, with the reviewed implementation and regression coverage. The release commit passed all 20 CI and distribution checks before publication. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since a1206b6 cache files store
base64_encode(gzcompress(serialize()))so large payloads do not become array literals that are expensive to parse and can exhaust CLI memory. That holds without OPcache. With OPcache the parse happens once per file version, while inflating and unserializing the compressed form runs on every include. A plain array file is compiled once into shared memory, and each include returns the immutable array without parsing or copying it.export_payload()now writes the plain array when the writing process serves includes from OPcache shared memory (opcache.enable, plusopcache.enable_clion the CLI, and notopcache.file_cache_only), and the compressed form otherwise. The newblockstudio/cache/compressfilter overrides the choice per scope, for example when WP-CLI without OPcache warms the cache for web workers that use it. The cache version moves to 7 so existing files are rewritten.Per include of the runtime payload (PHP 8.4). Real site with 28 blocks (398 KB serialized), and the same payload scaled to 560 blocks (7.1 MB):
Full page views (WordPress 7.1.3, forked in-process requests, ABAB, n=30, 4 rounds): 0.6 to 0.75 ms less per request on all three pages measured, and peak memory 14 → 12 MB.
Trade-offs:
opcache.file_update_protectionseconds (2 by default) after it was written, so requests in that window compile it themselves.Tests: the compact-format test forces compression through the filter. New tests cover the plain-array format (round trip including quotes, a backslash, a NUL byte, scalars and nested lists) and the default choice.
Independent of #173 (no conflicts when merged in either order).