From 33a1e60fcda5d1c849b5f4907d17304654a13496 Mon Sep 17 00:00:00 2001 From: Mika Cohen Date: Sun, 13 Sep 2026 15:53:05 -0600 Subject: [PATCH] bench: reuse multiline terminator Finder --- docs/development.md | 13 ++++++++++++- src/session/multiline_framing.rs | 8 +++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/development.md b/docs/development.md index ecbc7524..32296c6a 100644 --- a/docs/development.md +++ b/docs/development.md @@ -83,7 +83,18 @@ Current response responsibilities: ## Benchmarks -Published benchmark numbers were intentionally removed from the docs until they are rerun. +The stock cache-miss E2E harness ran on an AMD Ryzen 9 5950X with 32 logical +CPUs. `main` commit `145b36c6b86621dccfe965926b0ef501ffd33b06` and Finder +candidate commit `e176fef31432ed36dc101471dfa1c94cc1650908` each completed +the default 112-cell matrix twice for Finder (10 GiB per cell, 728,320-byte +articles, article-only mix, pipeline depth 32). The fresh main control's +equal-weight mean was 3,546.6 MiB/s; Finder repeats were 3,564.3 MiB/s +(+0.5%) and 3,560.8 MiB/s (+0.4%). Their paired medians were -0.4% and ++0.4%, geometric means +0.6% and -0.5%, and win/loss counts 50/62 and 63/49. +Measured proxy CPU changed -0.8% then +0.2%. The fresh main control was 0.8% +above the older main baseline. The repeats have substantial per-cell spread, +so they do not demonstrate a reliable end-to-end speedup. The fresh CSVs are +retained locally and are not committed. When you want fresh numbers: diff --git a/src/session/multiline_framing.rs b/src/session/multiline_framing.rs index b2fafbe2..181d15da 100644 --- a/src/session/multiline_framing.rs +++ b/src/session/multiline_framing.rs @@ -11,6 +11,7 @@ use std::borrow::Cow; use std::collections::VecDeque; use std::ops::Range; +use std::sync::LazyLock; use anyhow::Context; use smallvec::SmallVec; @@ -20,6 +21,9 @@ const TERMINATOR: &[u8; 5] = b"\r\n.\r\n"; const TERMINATOR_TAIL_SIZE: usize = 4; const MAX_CAPTURED_MULTILINE_RESPONSE_BYTES: usize = 4 * 1024 * 1024; +static TERMINATOR_FINDER: LazyLock> = + LazyLock::new(|| memchr::memmem::Finder::new(TERMINATOR)); + #[must_use] pub(crate) fn cached_response_completion() -> std::io::IoSlice<'static> { std::io::IoSlice::new(TERMINATOR) @@ -2056,7 +2060,9 @@ fn find_terminator_end(data: &[u8]) -> Option { #[inline] fn terminator_ends(data: &[u8]) -> impl Iterator + '_ { - memchr::memmem::find_iter(data, TERMINATOR).map(|found| found + TERMINATOR.len()) + TERMINATOR_FINDER + .find_iter(data) + .map(|found| found + TERMINATOR.len()) } #[inline]