Skip to content

test(benchmarks): enforce the 100ms startup injection budget - #1140

Merged
igorls merged 1 commit into
MemPalace:developfrom
arnoldwender:tests/perf-budget-regression
Aug 18, 2026
Merged

test(benchmarks): enforce the 100ms startup injection budget#1140
igorls merged 1 commit into
MemPalace:developfrom
arnoldwender:tests/perf-budget-regression

Conversation

@arnoldwender

Copy link
Copy Markdown
Contributor

What and Why

CLAUDE.md lists two non-negotiable latency targets under Design Principles:

  • Hooks under 500ms.
  • Startup injection under 100ms.

Until now those were prose claims with no enforcement. Any contributor could add an eager import chromadb to mempalace/__init__.py and the promise would silently regress. A lean package import is the concrete lower bound for both claims, so the first thing to protect is the import path.

Change Summary

Adds tests/benchmarks/test_performance_budgets.py with two regression tests that each run in a fresh Python subprocess — so the import is truly cold, not polluted by whatever pytest already loaded:

  • test_package_import_under_startup_budgetimport mempalace must finish under 100ms
  • test_cli_import_under_startup_budgetfrom mempalace import cli must also finish under 100ms; this is the path hooks take on invocation, so a regression adds latency to every Stop/PreCompact call before any real work begins

Budget is scaled 3× on CI (CI=true env var) to absorb shared-runner jitter without flaking.

Why tests/benchmarks/

Lives under tests/benchmarks/ so it is excluded from the default

pytest tests/ --ignore=tests/benchmarks

run — it does not slow the main CI loop. Invoke explicitly when validating performance-sensitive changes:

pytest tests/benchmarks/test_performance_budgets.py

If the maintainers prefer this to run in main CI, happy to move it and add a pytest -m perf marker instead.

Local Measurements

On macOS Python 3.13, three cold runs each:

Import p50
import mempalace ~6 ms
from mempalace import cli ~9 ms

Both comfortably under the 100ms target. The test fails when real drift appears, with an error message that points the reader at the most common cause (a new eager import in __init__.py).

Test Plan

  • pytest tests/benchmarks/test_performance_budgets.py -v — 2/2 pass
  • ruff check / ruff format --check — clean
  • Zero behavior change (tests-only addition, nothing runs in the default CI loop)

Follow-up (out of scope)

CLAUDE.md also claims Hooks under 500ms. Enforcing that requires a palace fixture and full hook invocation — a larger PR. If this approach is welcome I'll send a second PR for the hook budget using mempal_save_hook.sh against a tmp palace.

@igorls igorls added the performance Performance improvements label Apr 24, 2026
@arnoldwender
arnoldwender force-pushed the tests/perf-budget-regression branch 2 times, most recently from 1f490f9 to 7cd2941 Compare May 1, 2026 12:41
@arnoldwender
arnoldwender force-pushed the tests/perf-budget-regression branch from 7cd2941 to 52b0263 Compare May 4, 2026 09:08
@arnoldwender

Copy link
Copy Markdown
Contributor Author

Rebased on upstream/develop (latest 1247e17, post-3.3.5 release). No logical changes — conflict-free rebase, only commit replay onto current develop. CI green pre-rebase; awaiting fresh CI run.

@arnoldwender
arnoldwender force-pushed the tests/perf-budget-regression branch from 52b0263 to 5a8dff8 Compare May 10, 2026 10:57
@arnoldwender

Copy link
Copy Markdown
Contributor Author

Friendly ping — post-3.3.6 release this is still mergeable on upstream/develop @ f5ea021 (CI green, no conflicts). Happy to adjust anything if it would help land it.

@arnoldwender
arnoldwender force-pushed the tests/perf-budget-regression branch from 5a8dff8 to db46150 Compare May 30, 2026 12:47
@arnoldwender

Copy link
Copy Markdown
Contributor Author

Friendly ping — post-v3.5.0 status: this benchmark-only guard for the 100 ms startup-injection budget still merges clean (CI green). It only touches tests/benchmarks/, so zero production-code risk. Would appreciate a quick look when there's bandwidth.

CLAUDE.md lists two non-negotiable latency targets under Design Principles:

    - Hooks under 500ms.
    - Startup injection under 100ms.

Until now those were prose claims with no enforcement. Anyone could add an
eager 'import chromadb' to mempalace/__init__.py and the promise would
silently regress — a lean package import is the concrete lower bound for
both claims, so the first thing to protect is the import path.

Adds tests/benchmarks/test_performance_budgets.py with two tests that run
each measurement in a fresh Python subprocess (so the import is truly
cold, not polluted by whatever pytest already loaded):

  - 'import mempalace' must finish under 100ms (3x CI multiplier)
  - 'from mempalace import cli' must also finish under 100ms — this is
    the path hooks take, so a regression here adds latency to every
    Stop/PreCompact invocation before any real work begins

Lives in tests/benchmarks/ so it is excluded from the default
'pytest tests/ --ignore=tests/benchmarks' run and does not slow the main
CI loop. Invoke explicitly when validating performance-sensitive changes.

Local measurements right now:
  import mempalace           ~6ms
  from mempalace import cli  ~9ms

Both comfortably under the 100ms target; test failure means real drift.
@arnoldwender
arnoldwender force-pushed the tests/perf-budget-regression branch from db46150 to 6bbd6e9 Compare July 22, 2026 19:44
@arnoldwender

Copy link
Copy Markdown
Contributor Author

Rebased onto current develop (aa89bd8, post-v3.6.0) — clean, no conflicts, no logical changes.

Re-checked whether this is still a gap before re-surfacing it: tests/benchmarks/test_layers_bench.py has TestWakeUpTokenBudget, which guards the token budget for L0+L1 — there's still no guard on the startup-time budget. This PR adds tests/benchmarks/test_performance_budgets.py asserting package import and CLI import stay under STARTUP_BUDGET_MS = 100 (with a CI multiplier for runner noise).

Touches only tests/benchmarks/ — one new file, zero production code, so the blast radius is nil. CI is running fresh against the current base.

@igorls
igorls merged commit e40cdef into MemPalace:develop Aug 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants