dd-trace-php icon indicating copy to clipboard operation
dd-trace-php copied to clipboard

perf(prof): sample filtering and hashing

Open morrisonlevi opened this issue 3 months ago • 2 comments

PROF-12543

Key Changes

New EnabledProfiles structure for faster hashing

Encodes the enabled profile and sample types into a single integer. It replaces SampleTypeFilter in the ProfileIndex and SampleTypeFilter is now unused so it's removed. This speeds up Hash + Eq when used inside of ProfileIndex as a key in the hash map by the processing thread.

Sample values are inline instead of a Vec to unblock sooner

This replaces the Vec<i64> of samples in SampleData with SampleValues. It's converted into a Vec in the other thread. This offloads the CPU and memory work to the processing thread, which unblocks the thread taking the sample sooner.

New data structures InlineVec and BitSet

InlineVec<T, N> is a custom stack-allocated vector implementation that stores elements inline without heap allocation, similar to the arrayvec crate but with const fn support.

BitSet is a simple stack-allocated bitset backed by an integer. This means it doesn't allocate memory and operations on it are quick and simple, notably Hash and Eq are much cheaper (no iteration required).

Additional Notes

  • A small number of allocation failures in the other thread were converted to non-panic versions, instead dropping the sample. This moves the needle a bit but it isn't comprehensive.
  • This work is a stepping stone towards using the new profiling API, which has multiple profiles with only 1-2 sample types per profile. This influences the shape of the new APIs.
  • This PR is an opportunity for me to run a performance benchmark with Florian's new benchmarking tool!

Reviewer checklist

  • [ ] Test coverage seems ok.
  • [ ] Appropriate labels assigned.

morrisonlevi avatar Sep 16 '25 06:09 morrisonlevi

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 61.75%. Comparing base (b3136db) to head (4175238).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3416      +/-   ##
==========================================
- Coverage   61.90%   61.75%   -0.15%     
==========================================
  Files         141      141              
  Lines       12481    12481              
  Branches     1630     1630              
==========================================
- Hits         7726     7708      -18     
- Misses       4033     4051      +18     
  Partials      722      722              

see 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b3136db...4175238. Read the comment docs.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov-commenter avatar Sep 16 '25 06:09 codecov-commenter

Benchmarks [ profiler ]

Benchmark execution time: 2025-09-16 17:06:09

Comparing candidate commit 4175238edd8815d8b6925d8cb150a1a69feb0db3 in PR branch levi/sample-types with baseline commit b3136db3484958bd3430ed6a55067c7443d45fd4 in branch master.

Found 1 performance improvements and 0 performance regressions! Performance is the same for 28 metrics, 7 unstable metrics.

scenario:php-profiler-timeline-memory-with-profiler

  • 🟩 cpu_user_time [-87.421ms; -52.070ms] or [-7.295%; -4.345%]

pr-commenter[bot] avatar Sep 16 '25 06:09 pr-commenter[bot]