Skip to content

bench: criterion suite for the extension hot paths - #1474

Open
duncanista wants to merge 2 commits into
jordan.gonzalez/fault-harness/featurefrom
jordan.gonzalez/bench-suite/feature
Open

duncanista wants to merge 2 commits into
jordan.gonzalez/fault-harness/featurefrom
jordan.gonzalez/bench-suite/feature

Conversation

@duncanista

@duncanista duncanista commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: Criterion benchmarks for the hot paths: log processing, trace processing, invocation parsing, enhanced metrics, config load and init.

Why: The extension runs on about 0.07 vCPU at 128 MB, so per-line and per-span costs show up in the customer's billed duration. We need before and after numbers for each performance fix.

Overview

Jira: SVLS-9977

Stacked on #1473 (jordan.gonzalez/fault-harness/feature). It needs the fixtures and the dependency removal; the harness PR is only stacking order.

The extension runs at about 0.07 vCPU at 128 MB, so per-line, per-span and per-invocation
costs show up in billed duration. This PR adds 6 criterion benches (bottlecap/benches/):
logs, traces, invocation, enhanced_metrics, config, init. Benches named alt_*
measure an alternative from the review, as the target for a fix.

  • bottlecap/benches/README.md: what each bench measures, how to run it, noise control, the
    first baseline, and a table from each review item to its bench and number.
  • scripts/bench-compare.sh: save and compare criterion baselines with critcmp.
    scripts/bench-docker-arm64.sh: the suite in a 2-CPU Linux arm64 container.
  • Cargo.toml: criterion 0.5 as a dev-dependency (no plotters, no rayon), the 6 [[bench]]
    targets, and bench = false on the lib and binaries so cargo bench runs only criterion.
  • Production code: 8 items become #[doc(hidden)] pub so the benches can reach them
    (is_oom_error, the /proc readers *_from_path). No behavior change.
  • .gitignore: criterion exports and the Linux arm64 target dir.

Size: 270 core lines, 3032 lines in total.

Testing

  • applies on the previous PR of the stack: pass
  • cargo fmt --all -- --check: pass
  • cargo metadata --locked: pass
  • cargo clippy --workspace --all-targets --features default -- -D warnings: pass
  • cargo clippy --workspace --all-targets --features default,test-mode -- -D warnings: pass
  • cargo nextest run --workspace: pass
  • cargo bench --no-run (LTO off, 16 codegen units): pass
  • cargo deny --locked check: pass
  • cargo machete: pass
  • dd-rust-license-tool check: pass
  • shellcheck 0.10.0 on the new scripts: pass
  • Linux arm64 in Docker (rust 1.93.1), on the tree at the end of the stack: cargo clippy --workspace --all-targets --no-default-features --features fips -- -D warnings: pass. It cannot run on macOS (libddwaf-sys load error).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T21:19:49.643688Z ef8cf20 New commits
🔒 Security Review ✅ Completed 2026-10-28T21:21:05.622726Z ef8cf20 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 341f23b39d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/bench-docker-arm64.sh Outdated
fi
echo 'machine:' \$(uname -sm) \$(nproc) 'cpus visible,' \$(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2- || true)
echo 'profile:' \${CARGO_PROFILE_BENCH_LTO:+bench FAST (no LTO, NOT production)}\${CARGO_PROFILE_BENCH_LTO:-bench = release (opt-level z, lto, codegen-units 1)}
cargo bench ${benches[*]-} -- --save-baseline '$name' ${extra[*]-}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve Criterion arguments across the container shell

Because the collected arguments are interpolated as unquoted text into bash -c, valid Criterion filters containing spaces or shell metacharacters are re-parsed by the container shell. For example, scripts/bench-docker-arm64.sh main logs -- 'foo|bar' turns the filter into a pipeline rather than passing foo|bar to Criterion, so the benchmark fails or runs the wrong command. Pass the arrays as positional parameters to the inner shell (or otherwise shell-quote each element) instead of embedding ${extra[*]} and ${benches[*]} in the command string.

Useful? React with 👍 / 👎.

Comment thread scripts/bench-compare.sh

here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
crate="$here/bottlecap"
export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$crate/target}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve relative target directories before changing directories

When CARGO_TARGET_DIR is relative, as in the documented CARGO_TARGET_DIR=bottlecap/target-linux-arm64 scripts/bench-compare.sh compare ... command, it is exported unchanged and then Cargo or critcmp runs after cd "$crate". Cargo consequently resolves that example as bottlecap/bottlecap/target-linux-arm64, while the metadata checks and writes later in this script resolve it from the caller's directory as bottlecap/target-linux-arm64; saved results, notes, and comparisons therefore end up looking in different directories. Convert a supplied relative path to an absolute path before entering the crate.

Useful? React with 👍 / 👎.

Comment thread scripts/bench-compare.sh Outdated
(cd "$crate" && cargo bench ${benches[@]+"${benches[@]}"} -- --save-baseline "$name" ${extra[@]+"${extra[@]}"})
mkdir -p "$CARGO_TARGET_DIR/criterion"
printf '%s\nsaved: %s\ngit: %s\n' "$note" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
"$(git -C "$here" rev-parse --short HEAD 2>/dev/null || echo unknown)" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Record uncommitted changes in baseline metadata

In the documented before/after workflow, the optimized code is commonly benchmarked immediately after it is edited but before it is committed. rev-parse HEAD then records the same commit for both baselines even though the second binary contains working-tree changes, making the saved metadata misattribute the result and preventing later reproduction. Include the dirty state (and ideally a diff or tree identifier) in the note rather than recording only HEAD.

Useful? React with 👍 / 👎.

@datadog-prod-us1-4

This comment has been minimized.

@duncanista duncanista changed the title [SVLS-9977] bench: criterion suite for the extension hot paths bench: criterion suite for the extension hot paths Oct 28, 2026
- bench-docker-arm64.sh: pass the cargo arguments to the container shell as
  positional parameters, so criterion filters are not re-parsed.
- bench-compare.sh: make a relative CARGO_TARGET_DIR absolute before cd, so
  cargo, critcmp and the baseline notes use the same directory.
- bench-compare.sh: record a dirty marker and a hash of the uncommitted diff
  in the baseline notes.
- benches/README.md: drop the old branch name.
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