Repository navigation
feat: Evaluate flags that depend on other flags - #150
Open
linear-code[bot] wants to merge 3 commits into
Open
linear-code[bot] wants to merge 3 commits into
linear-code[bot] wants to merge 3 commits into
Conversation
Segment conditions can now read other flags via `$.flags.<name>`, resolved lazily with a cycle guard, mirroring flagsmith-engine. Flag results also carry a `variant` key. Bumps engine-test-data to v3.11.0. Generated with [Linear](https://linear.app/flagsmith/agent-session/d9c8ddc7-fa40-4842-80da-7e01be1b4f77) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Covers the flagsmith-engine CodSpeed contexts, the flag dependency cases, and local evaluation through the client. Generated with [Linear](https://linear.app/flagsmith/agent-session/d9c8ddc7-fa40-4842-80da-7e01be1b4f77) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
Skip the lazy flags when there are no segments, and break the context/flags reference cycle so each evaluation is freed by reference counting rather than left to the cycle collector. Generated with [Linear](https://linear.app/flagsmith/agent-session/d9c8ddc7-fa40-4842-80da-7e01be1b4f77) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
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.
Implements https://linear.app/flagsmith/issue/SDK-6/enable-flag-dependency-in-the-php-server-side-sdk
Ports flag dependency from flagsmith-engine#343. Segment conditions can now read other flags via
$.flags.<name>.enabled|value|variant.$.flagsis a newLazyFlags(ArrayAccess) bound to the context. It resolves each flag (including its segment overrides) the first time a condition reads it, and memoises segment matches. Any$.flagssupplied by the caller is discarded.ERROR; code=CIRCULAR_DEPENDENCY.FlagResultnow has avariantfield:control, the selected variant'skey, ornull.FeatureValueaccepts an optionalkey. The flag dependency test data requires both.STATICreason) is out of scope; Renovate's deps: update dependency tests/engine/enginetests/enginetestdata to v3.12.1 #138 tracks it.benchmarks/EngineBench.php). They use the same five contexts as flagsmith-engine's CodSpeed benchmark, the 19 flag dependency cases, and local evaluation through the client (tests/Data/environment.json).No release is included; the minor version release stays with a human.
Performance
Result: existing flag paths are not at parity. They are 4–5% slower than the baseline, which is 0.13–1.1 µs per call on these small inputs, and peak memory is back to baseline levels. The commit as first pushed (
e4a601b) was 7–31% slower and used up to 33 MB peak memory, because each evaluation left a context ↔LazyFlagsreference cycle for the cycle collector.1649a50breaks that cycle and skips the lazy flags when there are no segments.Setup:
351aeae(main before this PR).vendor/.tests/Data/environment.jsonfor every tree.modeper iteration, as the median of the three rounds (rstdev ≤ 2.3%).351aeaee4a601b1649a50benchEngine(5 CodSpeed contexts)benchLocalEvaluationEnvironmentFlagsbenchLocalEvaluationIdentityFlagsbenchEngineFlagDependency(19 cases)* Not comparable: the baseline can't resolve
$.flags, so it does none of the dependency work and returns wrong results for those cases.To reproduce:
composer install git worktree add ../baseline 351aeae && cp -a vendor ../baseline/ vendor/bin/phpbench run --bootstrap=../baseline/vendor/autoload.php --tag=baseline --store vendor/bin/phpbench run --ref=baseline --report=aggregateThe benchmarks are always loaded from this branch;
--bootstraponly swaps in the baseline'ssrc/through its autoloader.What's left and limitations:
LazyFlagsobject and a cycle check per segment. The rest is a few small per-call costs (the newvariantfield, theoverrideWinshelper) that each sit below the measurement noise.LazyFlagsdown to the JSONPath lookup instead of cloning per evaluation. It measured no faster, so I didn't keep it.