Skip to content

Box Onset in TailEvent::Event - #8281

Merged
danlapid merged 1 commit into
mainfrom
dlapid/box-tail-onset
Nov 7, 2026
Merged

danlapid merged 1 commit into
mainfrom
dlapid/box-tail-onset

Conversation

@danlapid

@danlapid danlapid commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

TailEvent::Event is a kj::OneOf, so it is as large as its largest alternative. Onset is 416 bytes on x86-64, while the next largest (SpanOpen, Exception) are 128. Every queued tail event, most of them logs, paid for an Onset that occurs once per session: sizeof(TailEvent) was 496 bytes.

This holds Onset in a kj::Own instead. sizeof(TailEvent) drops to 208 bytes, which more than halves the memory a streaming tail session holds for a backlog of short logs.

Found while investigating an edgeworker load test (streaming-trace-perf_1000) where a tail worker falling behind let the process accumulate 7 GiB of queued tail events. #8282 (stacked on this) bounds that memory.

🤖 Generated with Claude Code

TailEvent::Event is a OneOf, so it is as large as its largest
alternative. Onset is 416 bytes on x86-64; the next largest, SpanOpen
and Exception, are 128. Every queued tail event, most of them logs,
paid for an Onset that occurs once per session: sizeof(TailEvent) was
496 bytes.

Hold Onset in a kj::Own instead. sizeof(TailEvent) drops to 208 bytes,
which cuts the memory a streaming tail session holds for a backlog of
short logs by more than half.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — Mechanical boxing of Onset is applied consistently at every use; no issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

Every TailEvent::Event match, check and construction site now uses kj::Own<Onset>. Cloning makes a deep copy with kj::heap(onset->clone()), and the RPC read path builds the event on the heap. Behaviour does not change.


📝 Documentation: ✅ LGTM

The new comment in trace.h explains why Onset is boxed and describes the code as it is now.


Reviewed commit: 46a540d5

@danlapid
danlapid added this pull request to stack #8283 November 7, 2026 19:42
@danlapid
danlapid merged commit d3c66f6 into main Nov 7, 2026
23 of 25 checks passed
@danlapid
danlapid deleted the dlapid/box-tail-onset branch November 7, 2026 20:00
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.

2 participants