Skip to content

perf: lazy-import celpy and jsonschema (CLI startup ~2x faster)#53

Merged
fruwe merged 1 commit into
mainfrom
perf-lazy-imports
Jul 6, 2026
Merged

perf: lazy-import celpy and jsonschema (CLI startup ~2x faster)#53
fruwe merged 1 commit into
mainfrom
perf-lazy-imports

Conversation

@fruwe

@fruwe fruwe commented Jul 6, 2026

Copy link
Copy Markdown
Member

celpy (+ its lark/pendulum deps, ~0.1s) and jsonschema (~0.04s) were imported at module load, so even determa-state --version paid for them. Neither is needed to load/inspect/snapshot/step a machine — only to evaluate a guard/action (celpy) or validate structure (jsonschema).

Deferred both to first use. Guard-free paths no longer import them.

determa-state --version: ~370ms → ~170ms (warm; ~130ms interpreter floor here).

No behaviour change — 150 unit + 67 conformance green, ruff + mypy clean.

celpy (with its lark + pendulum deps, ~0.1s) and jsonschema (~0.04s) were
imported at module load, so every invocation — even determa-state --version —
paid for them. Neither is needed to load, inspect, snapshot, or step a machine:
celpy is only used to *evaluate* a CEL guard/action, jsonschema only to validate
a machine's structure.

Defer both to first use (celpy via a memoized loader in cel.py; jsonschema
inside validator._structural_errors). Guard-free paths (--version, --help,
state, enabled, send-from-store) no longer import them.

determa-state --version: ~370ms -> ~170ms (warm). No behaviour change:
150 unit + 67 conformance green, ruff + mypy clean.
@fruwe
fruwe merged commit d92c98c into main Jul 6, 2026
2 checks passed
@fruwe
fruwe deleted the perf-lazy-imports branch July 6, 2026 15:44
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