Skip to content

perf(profiling): scale Echion frame cache with frame limit - #20351

Draft
taegyunkim wants to merge 3 commits into
mainfrom
taegyunkim/prof-14213-scale-echion-frame-cache
Draft

taegyunkim wants to merge 3 commits into
mainfrom
taegyunkim/prof-14213-scale-echion-frame-cache

Conversation

@taegyunkim

@taegyunkim taegyunkim commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Scale Echion's retained frame cache to four times the configured maximum frame count, bounded between 256 and 1024 entries. Cache capacity can be adjusted while the sampler is stopped, and shrinking immediately evicts least-recently-used entries. With the default DD_PROFILING_MAX_FRAMES=64, this reduces the cache capacity from 1024 to 256 entries.

The retained frame-cache capacity is independent of the 2048-frame internal unwind safety ceiling, now named MAX_STACK_UNWIND_SAFETY_LIMIT after #20352. This PR leaves that ceiling and task-aware stack discovery unchanged.

JIRA: PROF-14213

Testing

Performance validation is deferred until #19085 and the PRs stacked on top of it have merged. Keep this PR in draft pending that evaluation. Refresh this branch against the resulting main, then compare the existing 1024-entry cache against 256/512-entry capacities and this scaling policy. Measure retained cache memory, process memory, cache hits/misses and evictions, sampler CPU time, and effective sampling frequency across plain-thread, asyncio, and gevent workloads. Re-run functional coverage on that baseline as well.

Completed functional checks on the current baseline:

  • Added native LRU cache coverage for capacity clamping and least-recently-used eviction on shrink. Native test execution is left to CI.
  • After merging origin/main at a1bcb762e9, rebuilt the native extensions and ran the following on Python 3.14.5 with gevent: 6 passed, 460 deselected.
    scripts/run-tests --venv 1b5fa93 -- tests/profiling/collector/test_stack.py \
      -k 'test_collect_truncate or test_native_frame_limit_scales_cache or test_exact_native_frame_limit_is_not_truncated or test_set_max_frames_after_fork_restart or test_asyncio_discovery_ignores_plain_stack_limit or test_collect_gevent_thread_task'
    Local Docker execution required a container-user override and a read-only mount of the worktree's Git metadata; the test runner and repository sources were unchanged.
  • scripts/lint checks: passed.
  • scripts/check-releasenotes: passed.
  • No benchmarks were run for this merge. Performance evaluation remains deferred as described above.

Risks

The smaller cache can increase frame-cache churn and sampler CPU overhead, even with shallow frame limits. The 256-entry floor only bounds minimum capacity, not miss rate or CPU cost: the shared cache working set depends on threads, tasks, and bytecode offsets, not just stack depth. Lower retained cache memory is the intended benefit, but neither its magnitude nor the overall performance tradeoff has been measured. The existing 1024-entry capacity remains the ceiling for larger limits.

Additional Notes

@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/echion/echion/cache.h          @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/echion/echion/echion_sampler.h  @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/include/constants.hpp          @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/sampler.cpp                @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/test/CMakeLists.txt            @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/test/test_cache.cpp            @DataDog/profiling-python
releasenotes/notes/profiling-scale-frame-cache-9c206653796fb780.yaml    @DataDog/apm-python
tests/profiling/collector/test_stack.py                                 @DataDog/profiling-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 1 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 201 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=132)
ddtrace.llmobs._integrations.vllm -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=130)
ddtrace.profiling.collector.pytorch -×-> ddtrace.trace  (product:profiling -> product:tracing, score=130)
ddtrace.llmobs._integrations.base -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=130)
ddtrace.internal.ci_visibility.api._base -×-> ddtrace.trace  (product:ci_visibility -> product:tracing, score=130)

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

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 2 Pipeline jobs failed

System Tests | serverless-system-tests / Build end-to-end (apigw-http)

View more details · View in GitHub Actions

System Tests | system-tests finished

View more details · View in GitHub Actions

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 9f12cf1 | Docs | View more details | Give us feedback!

taegyunkim added a commit that referenced this pull request Sep 21, 2026
Keep the existing fixed 1024-entry cache throughout the task-frame-budget work. Dynamic capacity management and its test expectations remain isolated in #20351 for after the rest of the stack lands.
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