perf: lazy-import celpy and jsonschema (CLI startup ~2x faster)#53
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
celpy(+ itslark/pendulumdeps, ~0.1s) andjsonschema(~0.04s) were imported at module load, so evendeterma-state --versionpaid 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.