Skip to content

fix(profiling): drop asyncio creator links for fire-and-forget tasks - #22110

Draft
taegyunkim wants to merge 1 commit into
mainfrom
taegyunkim/profiling-drop-creator-links
Draft

taegyunkim wants to merge 1 commit into
mainfrom
taegyunkim/profiling-drop-creator-links

Conversation

@taegyunkim

@taegyunkim taegyunkim commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

The stack profiler linked each asyncio.create_task child to its creator and drew it under the creator when nothing awaited it. Each child sample then carried whatever the creator was running at that moment, including the creator's own on-CPU frames.

This removes creator links on every Python version: the create_task hook, weak_link_tasks, and the sampler's weak-link map. A task nothing awaits now shows as its own root, as in CPython 3.15's sampling profiler. Links from await, gather, wait, as_completed, shield and TaskGroup are unchanged.

Customer impact

Fire-and-forget tasks appear as separate roots in flame graphs instead of under their creator, without the creator's frames. Release note included.

Testing

  • New test_asyncio_fire_and_forget.py fails on main and passes here.
  • test_asyncio_churn_links.py now churns gather links and runs under uvloop.
  • Ran the profiler asyncio/stack tests locally on 3.9-3.13 and 3.15, uvloop and gevent, plus the native stack gtests on 3.12. 3.14 left to CI.

Risks

Users lose the grouping of background tasks under their creator.

Additional Notes

PROF-16348. Not benchmarked; the change only removes work.

Tasks created with asyncio.create_task and never awaited were stitched under
their creator, so their samples included the creator's frames, often on-CPU
frames the creator ran at sample time. Render them as their own root task
instead, on every Python version. Await, gather, wait, shield and TaskGroup
links are unchanged.
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/internal/datadog/profiling/stack/__init__.pyi                   @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/_stack.pyi                     @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/echion/echion/echion_sampler.h  @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/include/sampler.hpp            @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/echion/threads.cc          @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/sampler.cpp                @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/stack.cpp                  @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/test/CMakeLists.txt            @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/test/test_task_links.cpp       @DataDog/profiling-python
ddtrace/profiling/_asyncio.py                                           @DataDog/profiling-python
releasenotes/notes/profiling-asyncio-fire-and-forget-tasks-34f25aad40b4c805.yaml  @DataDog/apm-python
tests/profiling/collector/test_asyncio_churn_links.py                   @DataDog/profiling-python
tests/profiling/collector/test_asyncio_fire_and_forget.py               @DataDog/profiling-python
tests/profiling/collector/test_asyncio_wrap_path.py                     @DataDog/profiling-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 22 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 22 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=103)
ddtrace.llmobs._integrations.base -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.internal.span_bus -×-> ddtrace._trace.span  (internal-core -> product:tracing, score=35)
ddtrace.llmobs._llmobs -×-> ddtrace._trace.span  (product:llmobs -> product:tracing, score=33)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@pr-commenter

pr-commenter Bot commented Nov 26, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-26 00:17:05

Comparing candidate commit 4ffc78f in PR branch taegyunkim/profiling-drop-creator-links with baseline commit 5fe87e7 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 572 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-721.256ns; +747.281ns] or [-6.763%; +7.007%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-37.651ns; +41.388ns] or [-5.881%; +6.464%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1907.156ns; +1918.486ns] or [-9.552%; +9.609%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-2028.210ns; +1638.071ns] or [-10.408%; +8.406%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-388.846ns; +366.412ns] or [-9.127%; +8.600%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-223.616ns; +232.292ns] or [-8.415%; +8.741%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-89.677ns; +89.473ns] or [-6.525%; +6.510%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4960.702ns; +4300.105ns] or [-10.174%; +8.819%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1003.813ns; +896.474ns] or [-9.766%; +8.721%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-57.734µs; +53.912µs] or [-9.843%; +9.191%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:packagespackageforrootmodulemapping-cache_off

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.

1 participant