Skip to content

optimize tracing hot paths and add OOM protection#2828

Open
theanuragg wants to merge 3 commits into
confident-ai:mainfrom
theanuragg:perf/tracing-benchmark-and-optimize
Open

optimize tracing hot paths and add OOM protection#2828
theanuragg wants to merge 3 commits into
confident-ai:mainfrom
theanuragg:perf/tracing-benchmark-and-optimize

Conversation

@theanuragg

Copy link
Copy Markdown

Improves the three hottest tracing code paths identified during profiling and adds OOM protection to TraceManager to prevent unbounded memory growth.

Changes

  • OOM safeguard — introduce a maxTraces config option (default 0 = unlimited). When the limit is exceeded, evict the oldest traces from both traces[] and activeTraces, preventing unbounded growth in long‑running eval pipelines.
  • createTraceApi — replace the recursive processSpans() closure with an explicit stack-based traversal to eliminate per‑level function call overhead when walking the span tree.
  • convertSpanToApiSpan — remove dead _inputData / _outputData variables and seven redundant property reassignments, and move metadata into the initial object literal for a tighter hot path.
  • createNestedSpansDict — inline the per‑call closure and drop the unused null‑coalescing logic around children for a simpler, cheaper span‑to‑dict conversion.

Performance

  • createTraceApi (10 spans): 140,746 ops/s → 157,416 ops/s (+11.8%)
  • createTraceApi (85 spans): 6,356 ops/s → 6,932 ops/s (+9.1%)
  • observe() wrapper (no-op): 336,238 ops/s → 362,916 ops/s (+7.9%)

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@theanuragg is attempting to deploy a commit to the Confident AI Team on Vercel.

A member of the Team first needs to authorize it.

@theanuragg theanuragg force-pushed the perf/tracing-benchmark-and-optimize branch from b584e80 to cc68f5d Compare July 2, 2026 03:32
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