perf(profiling): yield between collection and encoder starts #11325
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 397 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.358
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #11325"
general
weight: 0.35
BridgeAR
What does this PR do?
Adds event-loop boundaries between synchronous profile collection and encoder starts, in two separately reviewable commits:
1.
perf(profiling): yield after synchronous profile collection- Keep all profile capture/restart operations synchronous and inside the existing crashtracker serialization guard.
- Capture collection metadata/compression configuration, then yield with
setImmediatebefore starting any encoder.- Cover shutdown, stop during the new yield, and synchronous/asynchronous encoding failures.
2.
perf(profiling): stagger profile encoder starts- Replace the eager
profiles.map(async ...)launch with a loop that yields between encoder starts.- Keep the encoding/compression promises in flight and await them together afterward: this does not serialize entire encoding or compression operations.
- Verify that later encoders can start while an earlier encoding is pending, and that compression remains concurrent.
No public API or configuration change.
Motivation
Refs #11136.
encodeAsync()performs synchronous sizing before its first yield. Previously, that work for every profile was launched consecutively in the same synchronous prefix as collection/restart and JS profile construction. A post-capture yield prevents sizing from adding to that initial uninterrupted interval; staggering also separates the encoders' synchronous prefixes from each other.Essentially,
profiles.mapwould run all synchronous prefixes of eachencodeAsyncsequentially and in the same synchronous run. We deconstruct thatprofiles.mapinto a loop that yields to event loop between each such synchronous prefix, while allowing their asynchronous work to proceed concurrently. The first yield before first encode further allows some app work to happen after the synchronous restart of profilers.The yield stays outside
crashtracker.withProfilerSerializing(). All native profiles have already been captured/restarted before yielding, preserving the ordering needed bystop().This is a partial responsiveness improvement, not a complete fix for the issue: native signal waits and JS serialization remain synchronous. Yielding can increase collection completion time in exchange for allowing application work to run.
Additional Notes
Measurements
Used the workload from #11136, concurrency 20, a 65-second upload period, and sequential 140-second runs (two periodic collections per variant). Local runtime: Node v24.18.0, macOS arm64, Apple M5 Pro. These are not measurements on the customer's production hardware.
| Variant | Submission-adjacent maximum event-loop delay, cycles 1 / 2 |
| --- | ---: |
| Baseline | 56.9 / 50.1 ms |
| Initial yield only | 49.5 / 49.1 ms |
| Initial yield + staggered starts | 51.6 / 37.5 ms |
Traces directly confirm that both heap and wall sizing move outside the initial synchronous collection prefix. Baseline sizing contributed approximately 4–7 ms to that interval.
Jira: [SCP-1468]
[SCP-1468]: https://datadoghq.atlassian.net/browse/SCP-1468?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ