Reproducible snapshot benchmark of the list hot paths (throwaway --network none container, optionally against a worktree's backend), and the three new rules in CLAUDE.md's performance section. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
33 lines
1.6 KiB
Bash
Executable File
33 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# bench-lists.sh [backend-dir] — time the conversation-list hot paths against a
|
|
# SNAPSHOT of the live data, in a throwaway container of the deployed image.
|
|
#
|
|
# scripts/bench-lists.sh # the code baked into the image (= prod)
|
|
# scripts/bench-lists.sh "$PWD/backend" # a checkout's backend (a worktree)
|
|
#
|
|
# Copies the DB (sqlite .backup, WAL-safe) + JSON stores into a temp dir — the
|
|
# live /data is never mounted writable — and runs with --network none and one
|
|
# CPU, so the cron scheduler can't fire anything and numbers match the box's
|
|
# single-core-per-GIL reality. The rows it prints are what the SSE bus makes
|
|
# every open client pay after one transcript write.
|
|
set -euo pipefail
|
|
DATA="${AI_AGENT_DATA:-$HOME/homelab/services/ai-agent/data}"
|
|
IMAGE="${AI_AGENT_IMAGE:-homelab-ai-agent}"
|
|
CODE="${1:-}"
|
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
|
|
mkdir -p "$tmp/data/transcripts"
|
|
cp "$DATA"/*.json "$tmp/data/"
|
|
sqlite3 "$DATA/ai-agent.db" ".backup $tmp/data/ai-agent.db"
|
|
cp "$here/bench_lists.py" "$tmp/bench_lists.py"
|
|
code=(); wd=/app
|
|
if [ -n "$CODE" ]; then code=(-v "$CODE":/app-new:ro); wd=/app-new; fi
|
|
docker run --rm --network none --cpus 1 -w "$wd" "${code[@]}" \
|
|
-e PYTHONDONTWRITEBYTECODE=1 -e PYTHONPATH="$wd" \
|
|
-v "$tmp/data":/data -v "$DATA/transcripts":/data/transcripts:ro \
|
|
-v "$HOME/.claude/projects":/transcripts:ro \
|
|
-v "$HOME/.claude-work/projects":/transcripts-work:ro \
|
|
-v "$HOME/homelab/.claude":/workspace/.claude:ro \
|
|
-v "$tmp/bench_lists.py":/bench_lists.py:ro \
|
|
--entrypoint python "$IMAGE" /bench_lists.py 2>&1 | grep -v Warning
|