Skip to content

Avoid blocking context call at the Flags feature initialization#3194

Merged
0xnm merged 1 commit into
developfrom
nogorodnikov/avoid-blocking-context-call-flags-init
Feb 23, 2026
Merged

Avoid blocking context call at the Flags feature initialization#3194
0xnm merged 1 commit into
developfrom
nogorodnikov/avoid-blocking-context-call-flags-init

Conversation

@0xnm

@0xnm 0xnm commented Feb 20, 2026

Copy link
Copy Markdown
Member

What does this PR do?

A bit of performance improvement during the Flags initialization. As it is seen on the following image, when Flags feature is initialized there is a blocking call to get SDK context:

image

It takes the majority of the Flags feature initialization time and makes Flags feature the slowest to initialize.

This PR moves getting SDK context to the worker thread when it is really needed.

As a result, initialization now is cheaper.

image

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm
0xnm requested a review from a team as a code owner February 20, 2026 10:46
@0xnm
0xnm requested a review from typotter February 20, 2026 10:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c8238cc317

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +64 to +65
sdkCore.getFeature(Feature.FLAGS_FEATURE_NAME)
?.withContext(withFeatureContexts = setOf(Feature.RUM_FEATURE_NAME)) { datadogContext ->

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle missing feature context when updating evaluations

updateEvaluationsForContext always sets state to Reconciling, but the subsequent sdkCore.getFeature(...)? .withContext(...) call has no fallback path. If the feature scope is unavailable (for example after Datadog.stopInstance) or withContext skips its callback because core is no longer initialized, this method exits without calling onSuccess/onFailure and without moving state out of Reconciling, so callers can wait indefinitely for a completion that never comes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If SDK / feature / context is not available, then we don't need anything.

@datadog-datadog-prod-us1

This comment has been minimized.

@codecov-commenter

codecov-commenter commented Feb 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 52.38095% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.49%. Comparing base (699dce4) to head (c8238cc).
⚠️ Report is 248 commits behind head on develop.

Files with missing lines Patch % Lines
...in/kotlin/com/datadog/android/flags/FlagsClient.kt 0.00% 34 Missing ⚠️
...id/flags/internal/evaluation/EvaluationsManager.kt 87.10% 3 Missing and 1 partial ⚠️
...ternal/net/PrecomputedAssignmentsRequestFactory.kt 87.50% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3194      +/-   ##
===========================================
+ Coverage    71.26%   71.49%   +0.23%     
===========================================
  Files          929      928       -1     
  Lines        34442    34421      -21     
  Branches      5813     5813              
===========================================
+ Hits         24542    24607      +65     
+ Misses        8255     8208      -47     
+ Partials      1645     1606      -39     
Files with missing lines Coverage Δ
...com/datadog/android/flags/internal/FlagsFeature.kt 87.30% <100.00%> (+2.23%) ⬆️
...s/internal/net/PrecomputedAssignmentsDownloader.kt 100.00% <100.00%> (ø)
...ternal/net/PrecomputedAssignmentsRequestFactory.kt 75.00% <87.50%> (+1.67%) ⬆️
...id/flags/internal/evaluation/EvaluationsManager.kt 87.80% <87.10%> (-1.67%) ⬇️
...in/kotlin/com/datadog/android/flags/FlagsClient.kt 42.31% <0.00%> (+5.64%) ⬆️

... and 38 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@typotter typotter 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.

Thanks for the performance bump and refactoring!

.put("sdk_version", flagsContext.sdkVersion)
.put("sdk_version", datadogContext.sdkVersion)

private val DatadogContext.rumApplicationId: String?

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.

🧑‍🍳

@0xnm
0xnm merged commit 3d758ed into develop Feb 23, 2026
27 checks passed
@0xnm
0xnm deleted the nogorodnikov/avoid-blocking-context-call-flags-init branch February 23, 2026 09:05
@ncreated
ncreated restored the nogorodnikov/avoid-blocking-context-call-flags-init branch April 9, 2026 09:51
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.

4 participants