Skip to content

Benchmark harness and batch insert optimization - #8

Merged
tldev merged 3 commits into
mainfrom
benchmark/pipeline-optimization
Mar 31, 2026
Merged

tldev merged 3 commits into
mainfrom
benchmark/pipeline-optimization

Conversation

@tldev

@tldev tldev commented Mar 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add bin/benchmark-pipeline harness for systematic A/B testing (RI PBF, fresh PostGIS per run, per-stage timing to JSONL)
  • Replace single-row INSERTs in Rust derive with UNNEST batch inserts (~230k round-trips → ~50 queries)
  • Add ANALYZE in derive.sql before exit_poi_candidates spatial join

Expected impact

  • Rust derive stage: 10-50x speedup from batch inserts
  • derive.sql: better query plans from fresh statistics

Test plan

  • Run bin/benchmark-pipeline --runs 3 --label baseline on RI PBF
  • Compare against pre-optimization baseline
  • Validate full US build after local benchmarks pass

🤖 Generated with Claude Code

tldev and others added 3 commits March 31, 2026 16:55
Replace single-row INSERT loops with UNNEST-based batch inserts in all
Rust derive write paths (highway_edges, exit_corridors, corridors,
corridor_exits, reference_routes, reference_route_anchors). This reduces
100k+ individual queries to ~20 batched queries per table, eliminating
per-row round-trip overhead.

Also adds:
- bin/benchmark-pipeline: Karpathy autoresearch-style harness for
  measuring per-stage wall-clock times using Rhode Island PBF
- ANALYZE exits/pois in derive.sql before the spatial join so the
  query planner uses fresh statistics

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Move docker run out of bash -c subshell so DB_CONTAINER variable is
  visible to the cleanup trap
- Add double-check wait: pg_isready inside container + real SQL query
  from the runner network before proceeding
- Support OI_REPO_ROOT env var for running from outside the repo
- Remove bind-mounted data dir (use ephemeral container storage)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deferred indexes (derive.sql):
  Drop GiST indexes on exits/pois before bulk loading, rebuild in a
  single pass before the spatial join. Drop exit_poi_candidates index
  before its bulk insert, rebuild after directional pruning. Avoids
  per-row GiST maintenance during inserts.

Connection pool (main.rs):
  Reduce max_connections from 20 to 4. The derive pipeline runs all
  operations sequentially within transactions, so 20 connections were
  wasted overhead.

Benchmark harness:
  Pre-build the Rust binary before the benchmark loop and invoke it
  directly instead of via cargo run. Eliminates ~1.4s of cargo
  bookkeeping overhead per run.

RI benchmark results (median of 3 warm runs):
  Baseline (main):      5,983ms total
  + UNNEST batching:    5,215ms (-13%)
  + Deferred indexes:   4,541ms (-24%)
  + Direct binary:      3,200ms (-47%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tldev
tldev merged commit 4ba9d0f into main Mar 31, 2026
3 checks passed
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