Skip to content

perf: flatten OTLP rows with fewer copies - #157

Merged
VibeSWE merged 7 commits into
mainfrom
perf/otel-flatten-rows
Nov 24, 2026
Merged

VibeSWE merged 7 commits into
mainfrom
perf/otel-flatten-rows

Conversation

@VibeSWE

@VibeSWE VibeSWE commented Nov 24, 2026 •

Copy link
Copy Markdown

Description

Makes the OTLP flatteners (src/otel/logs.rs, traces.rs, metrics.rs) cheaper per row without changing the rows they produce.

  • Rows are moved into the result instead of cloned.
  • The per-record maps are sized up front. The size comes from the attributes actually inserted, capped at 128, and never from a count in the request: sizing from the raw attribute count let 200,000 valueless scope attributes in a 0.5 MiB body reserve 3.1 GiB (fixed in the last commit, with a test).
  • OTLP timestamps are formatted directly instead of through strftime.
  • Release-profile micro-benchmarks for the three flatteners are added as ignored tests.

Measured

Instructions per row in the flatten benchmarks, release build, against main:

Signal Change
Logs −38.6%
Traces −35.9%
Metrics −10.6%

The benchmark row digests are unchanged, so the rows are the same.

Verified

cargo test --lib: 1,428 passed, 0 failed.

This branch is independent of the protobuf PR. The chunked-ingest PR contains both.


This PR has:

  • been tested to ensure log ingestion and log query works.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

VibeSWE and others added 7 commits November 23, 2026 15:44
Ignored tests that flatten a fixed OTLP protobuf request for logs, metrics
and traces, plus per-function timings for timestamp formatting, attribute
conversion, row cloning and the metrics series hash. Each benchmark reports
nanoseconds per row and a digest of the rows, dumps them with OTEL_BENCH_DUMP
and never reads the PARSEABLE global, so a test-name filter can run it.

Written by a DeepSeek V4.1 Flash agent; reviewed and re-measured by Claude.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
process_resource_logs and process_resource_spans built every row, merged the
resource-level fields into it, then deep-cloned the finished row into the
output vector and dropped the original. The rows vector is local and used up
here, so take each row by value and move it into the output instead. Rows,
field names and field order are unchanged.

Logs benchmark: 126,443 -> 89,218 instructions/row (-29.4%)
Traces benchmark: 161,803 -> 110,797 instructions/row (-31.5%)

Written by a DeepSeek V4.1 Flash agent; reviewed and re-measured by Claude.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
flatten_log_record, flatten_span_record and the event, link, scope and
resource maps were built from an empty serde_json Map, which rehashes the
keys already inserted at each growth step (0, 3, 7, 14, 28, ...). Give them
the capacity their fixed fields and attributes need, and size the per-resource
and per-scope row vectors from the record counts.

Logs benchmark: 89,218 -> 85,048 instructions/row (-4.7%)
Traces benchmark: 110,797 -> 107,149 instructions/row (-3.3%)

Written by a DeepSeek V4.1 Flash agent; reviewed and re-measured by Claude.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
convert_epoch_nano_to_timestamp runs twice per log record, metric data point
and span, and chrono's formatter reparses the format string and builds a
DelayedFormat for every one of them: 252 ns per call. Convert the timestamp
with the same chrono call as before, then write the fields into a 30 byte
buffer with two-digit digit pairs: 24 ns per call. Years outside 0..=9999,
where %Y needs a sign, keep using the formatter; an i64 of nanoseconds cannot
reach them. A differential test compares both paths over the ends of the
range, every second of a day, hours across the range and 20k pseudorandom
values.

Logs benchmark: 85,048 -> 77,287 instructions/row (-9.1%)
Metrics benchmark: 86,317 -> 77,335 instructions/row (-10.4%)
Traces benchmark: 107,149 -> 101,727 instructions/row (-5.1%)

Written by a DeepSeek V4.1 Flash agent; reviewed and re-measured by Claude.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Written by a DeepSeek V4.1 Flash agent; reviewed and re-measured by Claude.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The pre-sizing added earlier on this branch took the capacity of resource,
scope and span maps from the request's attribute count. Those maps are cloned
into every row with their capacity, and an attribute without a value is two
bytes on the wire and is never inserted. A 0.5 MiB body of 200k valueless scope
attributes and 10k records made every row carry a map for 200k entries: about
3.1 GiB of resident memory, against 32 MiB with this change.

The hint now counts only the attributes that will be inserted and is capped at
128; larger maps grow as their entries arrive. Rows are unchanged, and the
flatten benchmarks move by at most +0.6% (logs 77,677 -> 78,177 instructions
per row; still -38.6% against main).

Found by an Opus 5.5 review of a later change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@VibeSWE VibeSWE added the performance Throughput, latency or resource cost label Nov 24, 2026
@VibeSWE
VibeSWE merged commit 8b55420 into main Nov 24, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Throughput, latency or resource cost

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant