Skip to content

chore: Add criterion benchmarks, profiling, and optimization documentation - #531

Merged
rholshausen merged 3 commits into
masterfrom
v2-engine-perf
May 26, 2026
Merged

chore: Add criterion benchmarks, profiling, and optimization documentation#531
rholshausen merged 3 commits into
masterfrom
v2-engine-perf

Conversation

@rholshausen

Copy link
Copy Markdown
Contributor

This pull request introduces a comprehensive performance benchmarking and profiling workflow for the V2 matching engine, along with new tooling and documentation to support ongoing optimisation. The changes add Criterion-based benchmarks, a dedicated profiling example for flamegraph analysis, and a detailed guide for future performance work. Minor test adjustments were also made to align with recent refactoring.

Performance Benchmarking and Profiling Infrastructure:

  • Added a new benches/v2_engine.rs file using Criterion, providing statistical benchmarking for four representative scenarios (text body, JSON equality, JSON with rules, headers + query) and separating plan build, execute, and end-to-end timings.
  • Added a profiling example examples/profile_engine.rs that exercises all key scenarios in a tight loop, intended for use with cargo flamegraph and other profilers.
  • Introduced a [profile.profiling] build profile in Cargo.toml to enable release optimisations while retaining debug symbols, improving profiler output.
  • Registered the new benchmark in pact_matching/Cargo.toml and added Criterion as a dev-dependency.

Documentation:

  • Added a detailed PERFORMANCE.md guide covering profiling tools, workflow, benchmark structure, and optimisation history, to help maintainers and contributors follow best practices for performance work.

Test Adjustments:

  • Updated test invocations of walk_tree in walk_tree_tests.rs to clone the node argument, matching the new function signature after recent refactoring. [1] [2] [3] [4] [5]

rholshausen and others added 3 commits May 19, 2026 10:31
…ng target for V2 engine

- Replace iai stub in benches/v2_engine.rs with criterion benchmarks covering
  four scenarios (text body, JSON equality, JSON with matching rules,
  headers+query), each split into build / execute / build+execute phases
- Add examples/profile_engine.rs as a standalone flamegraph target
- Add [profile.profiling] to workspace Cargo.toml (release speed + debug symbols)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…terpreter

Change walk_tree and all execute_* methods to take ExecutionPlanNode by value
instead of by reference. The interpreter now moves/transforms the plan tree
into the executed tree rather than cloning it.

Key changes:
- walk_tree: &ExecutionPlanNode -> ExecutionPlanNode; CONTAINER and PIPELINE
  branches use children.into_iter() instead of VecDeque::from(children.clone()),
  and push(child_result) instead of push(child_result.clone())
- execute_action and all ~25 execute_* methods: owned node, destructure at top
- validate_one/two/three_args and validate_args: take Vec<ExecutionPlanNode>
  directly, use into_iter() to move children to walk_tree
- evaluate_children: takes children: Vec<ExecutionPlanNode> by value
- execute_plan: clones plan_root once at entry (public API unchanged)

Benchmark results (execute phase):
  text body:        -30%
  JSON equality:    -35%
  JSON with rules:  -33%

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Documents the flamegraph → benchmark → fix → repeat workflow used to
optimise the V2 engine, including tool setup, how to read flamegraphs,
criterion baseline management, and when to stop optimising.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rholshausen
rholshausen merged commit dea1bb2 into master May 26, 2026
25 checks passed
@rholshausen
rholshausen deleted the v2-engine-perf branch May 26, 2026 23:11
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