Repository navigation
perf: compute the settings fingerprint once per settings version - #175
Merged
Merged
Conversation
Runtime_Context asks for Settings::fingerprint() for every resolved output path, so a page with a few blocks encoded all settings as JSON and hashed them dozens of times per request. The fingerprint is now kept together with the settings array it was computed from. Comparing the two is constant time while the settings are unchanged and still detects every change, including reloads and direct writes; reset() clears it.
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.
Settings::fingerprint()JSON-encodes all resolved settings and hashes them on every call.Runtime_Contextasks for it when it resolves output paths, so an uncached page view called it 69 times on a home page with 6 blocks (0.75 ms) and 21 times on a page with one block (0.25 ms).The fingerprint is now kept together with the settings array it was computed from. While the settings are unchanged,
===on the same array in memory returns immediately, so encoding and hashing run once per settings version. Any change still produces a new fingerprint: a reload builds a new array, a direct write (as some tests do through reflection) separates the array, andreset()clears the cached value.Measured on WordPress 7.1.3, PHP 8.4 with OPcache, forked in-process requests, ABAB, n=20, medians:
Independent of #173 (which removes some of the calls by reading asset outputs from the runtime cache) and #174.
Tests:
SettingsTestcovers the value (hash ofget_all()), repeated calls, a direct write to the settings and a reload through a settings filter. The unit suite shows the same results with and without the change;phpcsonsettings.php, PHPStan andnpm run checkpass.