Skip to content

fix(flags): reuse depth-limited dependency results only where they hold - #414

Merged
marandaneto merged 5 commits into
mainfrom
fix/flags-dependency-depth-tagging
Dec 2, 2026
Merged

marandaneto merged 5 commits into
mainfrom
fix/flags-dependency-depth-tagging

Conversation

@marandaneto

@marandaneto marandaneto commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

💡 Motivation and Context

Follow-up to #411. Near the depth limit of 100, a dependency whose branch was cut off and which then resolved through a later condition was cached, so a shorter path read a value that only held on the deep path. A cut-off dependency also stayed unresolved after the rest of its chain was resolved. The fix keeps such results (values or failures) out of the shared cache, in a per-evaluation map that stores the entry depth and a resolution version. A failure is reused at the same depth or deeper; a value only at the same depth. Either is reused only while the version is unchanged, and the version moves only when a cut-off or depth-limited key is later resolved (cached, or recorded as a path-independent failure). Checks run in this order: failures → cycle → depth/budget → depth-limited lookup. Results with a cycle beneath them are never stored. Behavior without depth or budget hits is unchanged, and unrelated flags in a bulk pass no longer re-trigger the deep chain.

The same fix is in PostHog/posthog-android#1026 and PostHog/posthog-ruby#406 (a follow-up to the merged PostHog/posthog-ruby#404).

💚 How did you test it?

  • New tests in tests/UnitTests/Features/FeatureEnrollmentTests.cs, written first and red on the previous caching, green now:
    • ValueResolvedThroughAFallbackAfterTheDepthLimitIsNotReusedFromAShallowerPath, DepthLimitFailureIsEvaluatedAgainAtTheSameDepthOnceItsTailIsCached
    • DepthLimitedValueIsNotReusedAtADeeperDepthWithinLimit, DepthLimitedValueIsNotReusedPastTheLimit, DepthLimitedValueIsEvaluatedAgainOnceItsOwnLaterConditionCachedTheTail
    • InterleavedUnrelatedFlagsDoNotExhaustDependencyBudgetForHealthyFlags (bulk pass, not ordered dependencies-first: 10,317 dependency evaluations before, 101 now)
    • ServerOnlyFailureOfACutOffDependencyInvalidatesADepthLimitedValue
    • DepthLimitedValueDoesNotBypassCycleDetectionInBulkEvaluation, DepthLimitedValueDoesNotBypassSelfCycleDetectionInBulkEvaluation, DepthLimitedValueComputedUnderACycleIsNotReused
    • AlternatingDepthsAboveADepthLimitedFallbackChainDoNotExhaustDependencyBudgetForHealthyFlags (a chain deeper than the limit referenced alternately from two depths in one bulk pass: 10,283 dependency evaluations before, 260 now)
    • ValueComputedUnderACycleWithoutDepthLimitIsNotReused
  • The existing deep-chain tests keep the same dependency evaluation counts (1870, 101, 0, 32).
  • UnitTests (2353) and UnitTests.AspNetCore (76) on net8.0 and net10.0, and dotnet format --verify-no-changes.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with a Claude coding agent following the maintainer's cross-SDK rule for depth-limited dependency results, the same rule as PostHog/posthog-ruby#404 and PostHog/posthog-android#1026. The new tests were written first and shown failing against the #411 caching. The "generation" is the evaluation-cache size, read when a depth-tagged result is recorded rather than when its evaluation starts, so entries cached by its own subtree don't force a re-evaluation; this kept the deep-chain evaluation counts unchanged. The depth limit is lowered for tests only through an internal init property.

A dependency that ran out of depth below it and then resolved through a later condition was cached, so a shallower reference read a value that only held on the deep path. A dependency that ran out of depth was also remembered as failed at that depth, so it stayed unresolved after another condition cached the rest of its chain.

A result or failure computed while the depth limit or budget cut off a branch below it is now kept outside the evaluation cache, with the depth it was reached at and the cache size when it was recorded. It is reused only at the same depth or deeper while the cache has not grown, and is evaluated again otherwise. A flag computed under such a cut-off is not cached at the top level either. Cycle failures are still never cached, and the evaluation counts of the deep-chain tests are unchanged.

Tests can lower the depth limit through an internal MaxDependencyDepth init property.
@marandaneto marandaneto self-assigned this Dec 1, 2026
@marandaneto
marandaneto marked this pull request as ready for review December 1, 2026 15:30
@marandaneto
marandaneto requested a review from a team as a code owner December 1, 2026 15:30
@veria-ai

veria-ai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-12-02T09:34:57.562066+00:00
Duration: 125375ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 253ms
Format Validation.Event Has Uuid ✅ 137ms
Format Validation.Event Has Lib Properties ✅ 111ms
Format Validation.Distinct Id Is String ✅ 117ms
Format Validation.Token Is Present ✅ 112ms
Format Validation.Custom Properties Preserved ✅ 118ms
Format Validation.Event Has Timestamp ✅ 112ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 124ms
Retry Behavior.Retries On 503 ✅ 8125ms
Retry Behavior.Does Not Retry On 400 ✅ 2118ms
Retry Behavior.Does Not Retry On 401 ✅ 2115ms
Retry Behavior.Respects Retry After Header ✅ 8121ms
Retry Behavior.Implements Backoff ✅ 22137ms
Retry Behavior.Retries On 500 ✅ 6118ms
Retry Behavior.Retries On 502 ✅ 6121ms
Retry Behavior.Retries On 504 ✅ 6118ms
Retry Behavior.Max Retries Respected ✅ 22135ms
Deduplication.Generates Unique Uuids ✅ 118ms
Deduplication.Preserves Uuid On Retry ✅ 6118ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 13131ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 6122ms
Deduplication.No Duplicate Events In Batch ✅ 119ms
Deduplication.Different Events Have Different Uuids ✅ 112ms
Compression.Sends Gzip When Enabled ✅ 111ms
Batch Format.Uses Proper Batch Structure ✅ 109ms
Batch Format.Flush With No Events Sends Nothing ✅ 107ms
Batch Format.Multiple Events Batched Together ✅ 117ms
Error Handling.Does Not Retry On 403 ✅ 2112ms
Error Handling.Does Not Retry On 413 ✅ 2113ms
Error Handling.Retries On 408 ✅ 6120ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 146ms
Request Payload.Flags Request Uses V2 Query Param ✅ 111ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 109ms
Request Payload.Flags Request Omits Authorization Header ✅ 111ms
Request Payload.Token In Flags Body Matches Init ✅ 113ms
Request Payload.Groups Round Trip ✅ 113ms
Request Payload.Groups Default To Empty Object ✅ 111ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 110ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 112ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 110ms
Request Lifecycle.No Flags Request On Init Alone ✅ 4ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 109ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 215ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 121ms
Retry Behavior.Retries Flags On 502 ✅ 1115ms
Retry Behavior.Retries Flags On 504 ✅ 1112ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 213ms

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

SDK performance: posthog-dotnet

5 changes worth reviewing: 5 observed regressions.

Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate.

Test Measurement Before PR With PR Change
Evaluate one boolean flag Allocated memory per operation 1.68 KiB/op 1.85 KiB/op 9.7% more memory
Evaluate a rollout flag Allocated memory per operation 1.78 KiB/op 1.95 KiB/op 9.2% more memory
Evaluate a multivariate flag Allocated memory per operation 1.82 KiB/op 1.99 KiB/op 9% more memory
Evaluate a property-filtered flag Allocated memory per operation 1.91 KiB/op 2.07 KiB/op 8.6% more memory
Evaluate a cohort-filtered flag Allocated memory per operation 1.94 KiB/op 2.1 KiB/op 8.5% more memory
View all results
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Capture and deliver events (4,096-byte payload, burst) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Capture and deliver events (32-byte payload, steady) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Capture and deliver events (4,096-byte payload, steady) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Queue an event (32-byte payload) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Queue an event (4,096-byte payload) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate all 10 flags Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate all 100 flags Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate all 1,000 flags Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate one boolean flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a cohort-filtered flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a flag (early match) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a flag (late match) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a flag (no match) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a property-filtered flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a regex-filtered flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a rollout flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a multivariate flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Capture and deliver events (32-byte payload, burst) Allocated memory per operation 5.37 KiB/op 5.37 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst) Time per operation 4.45 µs/op 4.49 µs/op 0.9% more time Not flagged
Capture and deliver events (32-byte payload, burst) idle_managed_heap_bytes (estimated) 822.48 KiB 822.48 KiB No observed change Not flagged
Capture and deliver events (32-byte payload, burst) Idle process memory (RSS) 55.09 MiB 55.1 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst) Observed peak process memory (RSS) 57.69 MiB 57.7 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst) Managed heap after settling (estimated) 2.24 MiB 2.24 MiB No observed change Not flagged
Capture and deliver events (32-byte payload, burst) Process memory after settling (RSS) 57.78 MiB 57.79 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst) Process CPU time per operation 4.48 µs/op 4.52 µs/op 0.8% more time Not flagged
Capture and deliver events (32-byte payload, burst) Lifetime peak process memory (RSS) 57.78 MiB 57.79 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Allocated memory per operation 39.87 KiB/op 39.87 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Time per operation 16.57 µs/op 16.64 µs/op 0.4% more time Not flagged
Capture and deliver events (4,096-byte payload, burst) idle_managed_heap_bytes (estimated) 2.13 MiB 2.13 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst) Idle process memory (RSS) 57.02 MiB 56.97 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Observed peak process memory (RSS) 82.14 MiB 82.15 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Managed heap after settling (estimated) 25.63 MiB 25.63 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst) Process memory after settling (RSS) 82.31 MiB 82.31 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Process CPU time per operation 18.18 µs/op 18.21 µs/op 0.2% more time Not flagged
Capture and deliver events (4,096-byte payload, burst) Lifetime peak process memory (RSS) 82.31 MiB 82.31 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady) Allocated memory per operation 18.15 KiB/op 18.15 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady) Time per operation 7.98 µs/op 8 µs/op 0.2% more time Not flagged
Capture and deliver events (32-byte payload, steady) idle_managed_heap_bytes (estimated) 822.48 KiB 822.48 KiB No observed change Not flagged
Capture and deliver events (32-byte payload, steady) Idle process memory (RSS) 55.07 MiB 55.01 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady) Observed peak process memory (RSS) 55.64 MiB 55.58 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady) Managed heap after settling (estimated) 938.29 KiB 938.29 KiB No observed change Not flagged
Capture and deliver events (32-byte payload, steady) Process memory after settling (RSS) 55.63 MiB 55.57 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady) Process CPU time per operation 8.12 µs/op 8.15 µs/op 0.3% more time Not flagged
Capture and deliver events (32-byte payload, steady) Lifetime peak process memory (RSS) 55.63 MiB 55.57 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Allocated memory per operation 30.97 KiB/op 30.96 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Time per operation 13.32 µs/op 13.1 µs/op 1.7% less time Not flagged
Capture and deliver events (4,096-byte payload, steady) idle_managed_heap_bytes (estimated) 2.13 MiB 2.13 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Idle process memory (RSS) 56.95 MiB 56.99 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Observed peak process memory (RSS) 63.97 MiB 63.7 MiB 0.4% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Managed heap after settling (estimated) 3.12 MiB 3.12 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Process memory after settling (RSS) 60.63 MiB 60.66 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Process CPU time per operation 15.45 µs/op 15.44 µs/op <0.1% less time Not flagged
Capture and deliver events (4,096-byte payload, steady) Lifetime peak process memory (RSS) 63.85 MiB 63.75 MiB 0.2% less memory Not flagged
Queue an event (32-byte payload) Allocated memory per operation 1.67 KiB/op 1.67 KiB/op No observed change Not flagged
Queue an event (32-byte payload) Time per operation 1.35 µs/op 1.35 µs/op 0.1% less time Not flagged
Queue an event (32-byte payload) Process CPU time per operation 1.37 µs/op 1.36 µs/op 0.1% less time Not flagged
Queue an event (4,096-byte payload) Allocated memory per operation 1.67 KiB/op 1.67 KiB/op No observed change Not flagged
Queue an event (4,096-byte payload) Time per operation 1.29 µs/op 1.31 µs/op 1% more time Not flagged
Queue an event (4,096-byte payload) Process CPU time per operation 1.3 µs/op 1.32 µs/op 0.8% more time Not flagged
Evaluate all 10 flags Allocated memory per operation 22.43 KiB/op 22.59 KiB/op 0.7% more memory Not flagged
Evaluate all 10 flags Time per operation 28.72 µs/op 28.9 µs/op 0.6% more time Not flagged
Evaluate all 10 flags Process CPU time per operation 28.73 µs/op 28.91 µs/op 0.6% more time Not flagged
Evaluate all 100 flags Allocated memory per operation 217.11 KiB/op 217.28 KiB/op <0.1% more memory Not flagged
Evaluate all 100 flags Time per operation 261.61 µs/op 262.75 µs/op 0.4% more time Not flagged
Evaluate all 100 flags Process CPU time per operation 261.72 µs/op 262.87 µs/op 0.4% more time Not flagged
Evaluate all 1,000 flags Allocated memory per operation 2.11 MiB/op 2.11 MiB/op <0.1% more memory Not flagged
Evaluate all 1,000 flags Time per operation 2.24 ms/op 2.25 ms/op 0.5% more time Not flagged
Evaluate all 1,000 flags Process CPU time per operation 2.24 ms/op 2.25 ms/op 0.5% more time Not flagged
Evaluate 1,000 flags under concurrent load idle_managed_heap_bytes (estimated) 4.77 MiB 4.77 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load Idle process memory (RSS) 108.24 MiB 108.34 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load Observed peak process memory (RSS) 113.96 MiB 114.02 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load Managed heap after settling (estimated) 4.87 MiB 4.87 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load Process memory after settling (RSS) 114.07 MiB 114.13 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load Lifetime peak process memory (RSS) 114.07 MiB 114.13 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions idle_managed_heap_bytes (estimated) 19.58 MiB 19.55 MiB 0.1% less memory Not flagged
Refresh 1,000 flag definitions Idle process memory (RSS) 140.85 MiB 140.78 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions Observed peak process memory (RSS) 148.98 MiB 149.04 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions Managed heap after settling (estimated) 20.57 MiB 20.54 MiB 0.1% less memory Not flagged
Refresh 1,000 flag definitions Process memory after settling (RSS) 147.97 MiB 148.1 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions Lifetime peak process memory (RSS) 148.49 MiB 148.43 MiB <0.1% less memory Not flagged
Evaluate one boolean flag Allocated memory per operation 1.68 KiB/op 1.85 KiB/op 9.7% more memory Worth reviewing: observed regression
Evaluate one boolean flag Time per operation 2.21 µs/op 2.29 µs/op 3.6% more time Not flagged
Evaluate one boolean flag Process CPU time per operation 2.21 µs/op 2.29 µs/op 3.6% more time Not flagged
Evaluate a cohort-filtered flag Allocated memory per operation 1.94 KiB/op 2.1 KiB/op 8.5% more memory Worth reviewing: observed regression
Evaluate a cohort-filtered flag Time per operation 2.21 µs/op 2.29 µs/op 3.6% more time Not flagged
Evaluate a cohort-filtered flag Process CPU time per operation 2.21 µs/op 2.29 µs/op 3.6% more time Not flagged
Evaluate a flag (early match) Allocated memory per operation 3.54 KiB/op 3.7 KiB/op 4.6% more memory Not flagged
Evaluate a flag (early match) Time per operation 3.5 µs/op 3.55 µs/op 1.6% more time Not flagged
Evaluate a flag (early match) Process CPU time per operation 3.5 µs/op 3.55 µs/op 1.6% more time Not flagged
Evaluate a flag (late match) Allocated memory per operation 5.14 KiB/op 5.32 KiB/op 3.4% more memory Not flagged
Evaluate a flag (late match) Time per operation 4.68 µs/op 4.68 µs/op 0.1% less time Not flagged
Evaluate a flag (late match) Process CPU time per operation 4.68 µs/op 4.68 µs/op 0.1% less time Not flagged
Evaluate a flag (no match) Allocated memory per operation 4.93 KiB/op 5.08 KiB/op 3.1% more memory Not flagged
Evaluate a flag (no match) Time per operation 4.08 µs/op 4.12 µs/op 1.2% more time Not flagged
Evaluate a flag (no match) Process CPU time per operation 4.08 µs/op 4.13 µs/op 1.2% more time Not flagged
Evaluate a property-filtered flag Allocated memory per operation 1.91 KiB/op 2.07 KiB/op 8.6% more memory Worth reviewing: observed regression
Evaluate a property-filtered flag Time per operation 2.1 µs/op 2.18 µs/op 4.1% more time Not flagged
Evaluate a property-filtered flag Process CPU time per operation 2.1 µs/op 2.18 µs/op 4.1% more time Not flagged
Evaluate a regex-filtered flag Allocated memory per operation 6.34 KiB/op 6.5 KiB/op 2.6% more memory Not flagged
Evaluate a regex-filtered flag Time per operation 6.96 µs/op 6.94 µs/op 0.3% less time Not flagged
Evaluate a regex-filtered flag Process CPU time per operation 6.98 µs/op 6.95 µs/op 0.4% less time Not flagged
Evaluate a rollout flag Allocated memory per operation 1.78 KiB/op 1.95 KiB/op 9.2% more memory Worth reviewing: observed regression
Evaluate a rollout flag Time per operation 2.65 µs/op 2.75 µs/op 3.6% more time Not flagged
Evaluate a rollout flag Process CPU time per operation 2.65 µs/op 2.75 µs/op 3.6% more time Not flagged
Evaluate a multivariate flag Allocated memory per operation 1.82 KiB/op 1.99 KiB/op 9% more memory Worth reviewing: observed regression
Evaluate a multivariate flag Time per operation 2.35 µs/op 2.45 µs/op 4.4% more time Not flagged
Evaluate a multivariate flag Process CPU time per operation 2.35 µs/op 2.45 µs/op 4.4% more time Not flagged

Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals.

Compared f69acdb32159b5d404614a8a9438b4a6adbb470d → a59d0a659641231acd7b1f5dac5e161ab55a1a04.

Full report and diagnostics

108 metric rows; 108 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating depth-limited results from evaluationCache fixes the two targeted scenarios cleanly, and the PostHog / PostHog.AspNetCore changesets and internal MaxDependencyDepth hook look good. Left three concerns inline before approval (two regressions relative to main in EvaluateAllFlags budget exhaustion and cycle-detection ordering, plus reusing non-failure depth-limited values at deeper depths), along with two optional suggestions on cache-invalidation edge cases.

AI-assisted review.

Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
@dustinbyrne
dustinbyrne requested a review from a team December 1, 2026 16:24
…ut-off resolves

A depth-limited value was reused deeper than where it was computed, even past the depth limit, and before the cycle check, so a cycle re-entering a flag read an earlier fallback instead of being detected. Results were invalidated by the evaluation cache size, which a flag's own later condition could grow unnoticed, a server-only failure did not grow at all, and every unrelated flag of a bulk evaluation grew, so a chain deeper than the limit was walked again per flag until the budget ran out and healthy flags were left unresolved.

Checks now run in order: path-independent failures, cycles, depth limit and budget, then depth-limited results. A resolution version replaces the cache size: it changes only when a flag that was cut off or has a depth-limited result is cached, at the top level too, or recorded as a path-independent failure. The version is read before the flag is evaluated. A failure is reused at the same depth or deeper and a value only at the same depth, and neither is stored when a cycle was hit below it.

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9007dd60 cleanly resolves all five earlier findings (confirmed locally: all 23 SkippedTargetingDependencies tests and all 7 Round-1 regression tests now pass). Left one new concern inline: pairing exact-depth value reuse with a single-slot DepthLimitedResults[flagKey] dictionary causes alternating-depth thrashing in bulk evaluation and can exhaust the 10,000 dependency budget for unrelated healthy flags. Also left two optional suggestions on CycleHits cache-guard symmetry and trimming the unshipped Round-1 regression from the changesets.

AI-assisted review.

Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
@dustinbyrne
dustinbyrne requested a review from a team December 1, 2026 18:04
…hallowest depth

Values computed under a depth or budget cut-off are stored per (flag key, depth), and
failures per flag key at the shallowest failing depth of the current resolution version,
so references to a deep fallback chain from different depths no longer evict each
other's result and re-walk the chain until the dependency budget runs out.
…ogress

Both the top-level and the dependency evaluation cache writes now skip a value whose
evaluation hit a cycle, matching the failure path and the other SDKs. The value is
still returned.

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All earlier review items are cleanly addressed in d2297e3 and a59d0a6 — splitting depth-limited values per (flagKey, depth) from shallowest-depth failures eliminates the alternating-depth bulk thrashing, both evaluationCache success writes now guard on CycleHits, and both changesets accurately reflect the delta against main. Verified locally (25/25 SkippedTargetingDependencies tests passing) alongside 24/24 green CI checks. Looks good to merge.

AI-assisted review.

@marandaneto

Copy link
Copy Markdown
Member Author

Re the SDK performance report: the ~9% (~170 B/op) allocation increase on single-flag evaluation came from DependencyEvaluationState eagerly allocating the depth-limited key set and the value/failure dictionaries on every evaluation. Fixed in a0695af by creating them only when first needed, since most evaluations never hit the depth limit or the budget. Measured allocations per EvaluateFeatureFlag call for a single boolean flag (net8.0 Release, 100k iterations after warmup): main 1,599 B, before the fix 1,770 B, after the fix 1,542 B. All 2,353 unit tests pass.

@marandaneto
marandaneto merged commit 6d43d77 into main Dec 2, 2026
22 checks passed
@marandaneto
marandaneto deleted the fix/flags-dependency-depth-tagging branch December 2, 2026 09:35
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