Repository navigation
[FFL-2785] Reduce flags provider initialization latency - #3078
gh-worker-dd-mergequeue-cf854d[bot] merged 39 commits into
Conversation
9ea3a06 to
31463c3
Compare
There was a problem hiding this comment.
More details
Comprehensive state machine validation completed. The PR successfully refactors FlagsRepository to avoid blocking provider initialization on the initial disk cache read by implementing an asynchronous callback-based approach and consolidating state under atomic locks. Version-based race prevention, disk-cache separation, and context-matching logic are sound. All critical timing variations are handled correctly by the test suite.
📊 Validated against 12 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit 58cb7b8 · What is Autotest? · Any feedback? Reach out in #autotest
leoromanovsky
left a comment
There was a problem hiding this comment.
Ran locally; yes, I believe this will fix the customer issue in the happy path.
My reading, though, is that if there is a network outage, we'll still see a long startup delay. I think it lacks an assertion that initialization has an upper latency bound when both cache and network paths are unhealthy.
e6d98c6 to
4e24256
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4e24256a3a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 97c2955afc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 91ee41044b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c05b791191
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 502dbbd6d6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
What and why?
Reduce flag-provider startup latency by removing unnecessary waits around the assignment request. Today,
setProviderAndWait()waits for the initial cache read before fetching, runs request setup on Core's shared context queue, and waits for cache encoding/persistence setup before reporting.ready.Demonstrated benefit: in a controlled Simulator test with a mocked response and a two-second storage-queue backlog, median repository initialization dropped from 2,041 ms to 0.21 ms across ten samples per version. Every PR sample completed before the cache read finished. This confirms removal of the cache dependency, not end-to-end
setProviderAndWait()or app-startup latency.How?
.utilityQoS. This isolates work without raising its priority above other SDK features.Allowing cache reads, fetches, and persistence to overlap requires explicit ordering guards so late work cannot overwrite newer assignments or undo reset.
Changes are confined to
DatadogFlags; no public API, Core queue priority, or network timeout changes. The required Core context snapshot can still wait behind shared work, tracked separately in FFL-3328. If startup remains slow, timing logs should confirm whether this remaining wait is responsible before pursuing that follow-up.Suggested review order
FlagAssignmentsFetcher.swift: request/response queue isolation and completion delivery.FlagsRepository.swift: overlapping fetch/cache work, matching-cache fallback, result ordering, and persistence.FlagsStateManager.swift: state updates under lock, with superseded notifications skipped outside the lock.Supporting diagnostics, cache behavior, and validation
Customer Evidence
Separate customer debugging runs showed approximately 10.5 seconds before fetching and 8.9 seconds between fetch success and
.ready. These were observed delays, not artificially injected; the competing work responsible was not confirmed.Controlled Benchmark
October 20, 2026: comparing
developat 176506095 with this PR at 215c81f.Ten samples per scenario and version, excluding one warmup. Measured repository construction through context-update completion on the Simulator, using real Core queues and mocked network responses.
Every storage-blocked PR sample completed before the cache read finished. The required Core context-snapshot wait remains. These results demonstrate removal of a queue dependency, not expected customer startup times.
Behavior Preserved
.stale) or.error.nil. Later updates have no initialization timeout; timing out does not cancel the fetch.Validation
All 200 Flags tests passed, including cache/concurrency regressions and flag-key obfuscation coverage. Targeted SwiftLint also passed.
Tests and benchmarks ran with Xcode 26.2, iPhone 17 / iOS 26.2 Simulator, Debug, on an Apple M3 Max. Both used
SWIFT_VERSION=5because existing DatadogTrace/OpenTelemetry errors blocked the default Swift 6 build locally.Review checklist
make api-surfacewhen adding new APIsNo public or Objective-C API changes; the last two checklist items are not applicable.
Metadata
Changelog:
DatadogFlagsassignments request without waiting for the initial cache read, and report successful assignments before cache persistence.FlagsClient.setEvaluationContextcalls no longer let an earlier result replace assignments for a newer context.