Skip to content

Incremental engine for long horizon agents 🌟 Star if you like it!

test(rust-sdk): bench warm component-memo hits under mount_each (#2782)

LJ πŸ₯₯🌴53c44a42ea38
diff --git a/benchmarks/file_summarization/README.md b/benchmarks/file_summarization/README.md
index c281ac46..f80ba8be 100644
--- a/benchmarks/file_summarization/README.md
+++ b/benchmarks/file_summarization/README.md
@@ -154,9 +154,11 @@ trustworthy.
Under the hood the runner will:
-1. Build the Rust binary (`rust/`) in release mode.
-2. Create `.work/<scenario>/<profile>/<scale>/trial_NN/` with fresh dataset,
- state, and output dirs.
+1. Build the Rust binary (`rust/`) in release mode, into `CARGO_TARGET_DIR`
+ when set, else `rust/target`.
+2. Create `.work/<scenario>/<profile>/<scale>/trial_NN/` (under
+ `BENCH_WORK_DIR` instead of `.work/` when set) with fresh dataset, state,
+ and output dirs.
3. For each of `cold / warm / edit / shape`: run Rust, run Python, compare
the output trees' hashes.
4. Aggregate medians across trials and print a per-phase table.
diff --git a/benchmarks/file_summarization/python/runner.py b/benchmarks/file_summarization/python/runner.py
index dd075c08..60274212 100644
--- a/benchmarks/file_summarization/python/runner.py
+++ b/benchmarks/file_summarization/python/runner.py
@@ -21,9 +21,13 @@ from common import (
PY_DIR = Path(__file__).resolve().parent
BENCH_ROOT = PY_DIR.parent
RUST_MANIFEST = BENCH_ROOT / "rust" / "Cargo.toml"
-RUST_BIN = BENCH_ROOT / "rust" / "target" / "release" / "file_summarization"
+RUST_BIN = (
+ Path(os.environ.get("CARGO_TARGET_DIR", BENCH_ROOT / "rust" / "target"))
+ / "release"
+ / "file_summarization"
+)
PYTHON_BIN = PY_DIR / "benchmark.py"
-WORK_ROOT = BENCH_ROOT / ".work"
+WORK_ROOT = Path(os.environ.get("BENCH_WORK_DIR", BENCH_ROOT / ".work"))
PHASES = ("cold", "warm", "edit", "shape")
diff --git a/rust/sdk/cocoindex/benches/README.md b/rust/sdk/cocoindex/benches/README.md
index b1e40360..06679230 100644
--- a/rust/sdk/cocoindex/benches/README.md
+++ b/rust/sdk/cocoindex/benches/README.md
@@ -23,7 +23,7 @@ live under [`benchmarks/`](../../../../benchmarks/) at the repository root.
| Group | Benchmark ids | Reported as |
| ----- | ------------- | ----------- |
| `memo_call` | `hit/small`, `hit/large_100k`, `miss/small`, `miss/large_100k` | per call of a `#[cocoindex::function(memo)]`, inside one update |
-| `component_overhead` | `mount_each/warm/{1000,10000}`, `use_mount/warm/{1000,10000}` | per trivial component on a warm run |
+| `component_overhead` | `mount_each/warm/{1000,10000}`, `mount_each_memo/warm/{1000,10000}`, `use_mount/warm/{1000,10000}` | per trivial component on a warm run: `mount_each` children run and commit, `mount_each_memo` children are component-memo hits |
| `fingerprint` | `from_vec/{1k,100k,10m}`, `from_bytes/{1k,100k,10m}` | bytes per second of `Fingerprint::from(&Vec<u8>)` against `Fingerprint::from_bytes` |
| `target_reconcile` | `cold/10000`, `no_change/10000` | per row declared into a counting no-op `TargetHandler` |
| `batched_fn` | `concurrent_calls/{1000,10000}` | per call of a `#[cocoindex::function(batching)]` with a trivial body |
diff --git a/rust/sdk/cocoindex/benches/sdk_engine.rs b/rust/sdk/cocoindex/benches/sdk_engine.rs
index d69a54ca..b856e2e8 100644
--- a/rust/sdk/cocoindex/benches/sdk_engine.rs
+++ b/rust/sdk/cocoindex/benches/sdk_engine.rs
@@ -14,8 +14,10 @@
//! with a small (`i64`) and a large (~100 KB string) argument. Reported
//! per call: the loop runs inside one `App::update`.
//! 2. `component_overhead` β€” a warm run over N trivial components, through
-//! `Ctx::mount_each` and through sequential `Ctx::scope` (`use_mount!`).
-//! Reported per component.
+//! `Ctx::mount_each` (no component memo: every child runs and commits),
+//! through `mount_each!` of a logic-tracked function keyed by file-name
+//! strings (every child is a component-memo hit), and through sequential
+//! `Ctx::scope` (`use_mount!`). Reported per component.
//! 3. `fingerprint` β€” `Fingerprint::from(&Vec<u8>)` (serde path) against
//! `Fingerprint::from_bytes` at 1 KB, 100 KB and 10 MB.
//! 4. `target_reconcile` β€” 10,000 rows declared into a counting no-op
@@ -226,6 +228,27 @@ async fn mount_each_run(app: &App, n: usize) -> Duration {
.unwrap()
}
+/// A logic-tracked child component: a warm run reuses its component memo.
+#[cocoindex::function]
+async fn memo_hit_child(_ctx: &Ctx, idx: i64) -> Result<()> {
+ black_box(idx);
+ Ok(())
+}
+
+async fn mount_each_memo_run(app: &App, n: usize) -> Duration {
+ app.update(move |ctx| async move {
+ let start = Instant::now();
+ let items = (0..n).map(|i| (format!("file_{i:05}.md"), i as i64));
+ cocoindex::mount_each!("files", items, |idx| memo_hit_child(ctx, idx))
+ .await?
+ .ready()
+ .await?;
+ Ok(start.elapsed())
+ })
+ .await
+ .unwrap()
+}
+
async fn scope_run(app: &App, n: usize) -> Duration {
app.update(move |ctx| async move {
let start = Instant::now();
@@ -260,6 +283,20 @@ fn bench_component_overhead(c: &mut Criterion) {
});
});
+ let fixture = rt.block_on(temp_app("mount_each_memo_warm"));
+ rt.block_on(mount_each_memo_run(&fixture.app, n));
+ group.bench_function(BenchmarkId::new("mount_each_memo/warm", n), |b| {
+ b.iter_custom(|iters| {
+ rt.block_on(async {
+ let mut total = Duration::ZERO;
+ for _ in 0..iters {
+ total += mount_each_memo_run(&fixture.app, n).await;
+ }
+ total
+ })
+ });
+ });
+
let fixture = rt.block_on(temp_app("scope_warm"));
rt.block_on(scope_run(&fixture.app, n));
group.bench_function(BenchmarkId::new("use_mount/warm", n), |b| {