Repository navigation
Conversation
In a sandboxed template, each attribute read on an object looped over all allowed classes with `instanceof` and `in_array()`. The policy now remembers the allowed (class, member) pairs, because the answer only depends on those two. Denials are never remembered and throw as before, and `setAllowedMethods()` and `setAllowedProperties()` clear the memo. With a policy of 20 classes, `checkMethodAllowed()` goes from 962-982 -> 58-67 ns. A sandboxed render with 900 attribute reads goes from 4.772-5.012 -> 3.885-4.056 ms. The new `SecurityPolicyTest` passes on 3.x too.
Kocal
force-pushed
the
perf/sandbox-policy-memo
branch
from
November 15, 2026 08:05
7b46a1a to
ed84664
Compare
nicolas-grekas
approved these changes
Nov 15, 2026
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.
In a sandboxed template, each attribute read on an object looped over all allowed classes with
instanceofandin_array().The policy now remembers the allowed (class, member) pairs, because the answer only depends on those two. Denials are never remembered and throw as before, and
setAllowedMethods()andsetAllowedProperties()clear the memo.With a policy of 20 classes,
checkMethodAllowed()goes from 962-982 -> 58-67 ns. A sandboxed render with 900 attribute reads goes from 4.772-5.012 -> 3.885-4.056 ms. The newSecurityPolicyTestpasses on 3.x too.