Repository navigation
perf: flatten OTLP rows with fewer copies - #157
Merged
Merged
Conversation
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>
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Makes the OTLP flatteners (
src/otel/logs.rs,traces.rs,metrics.rs) cheaper per row without changing the rows they produce.strftime.Measured
Instructions per row in the flatten benchmarks, release build, against
main: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:
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.