Repository navigation
perf: prune irrelevant actions, rehydrate plans and history lazily - #91
Merged
Merged
Conversation
…plies A* and MCTS drop, before searching, every action whose effects touch no goal-relevant key: the goal's keys and, by backward closure, the precondition keys of actions that write relevant keys. Reachable but useless actions used to multiply the state space by every combination of the facts they set; a chain of 6 layers with 2 such actions per layer explored 377 nodes in 93 ms and now 7 nodes in 0.4 ms, and shapes that did not finish within 10 minutes plan in milliseconds. Pruning is skipped when a relevant action has callable effects, which may read any key, and MCTS keeps every action when none writes a goal key so its anytime fallback still makes progress. A* also no longer copies the state for an action whose effects already hold. Adds the distractor benchmark.
Every graph node rehydrates the state from the channel; rebuilding one PlanningState per plan step and one ActionResult per history entry on every node made a run quadratic in its length. Plan.from_dict and history_from_state now return LazyStates and LazyHistory, which build each entry the first time it is read and compare, index, slice and concatenate like the tuple and list they replace. In the benchmark suite a 60-step run went from 306 ms to 99 ms and a 120-step run from 1121 ms to 198 ms. Adds the long-loop benchmark.
PlanningState.apply builds the new frozenset from the cached view without re-probing every value for hashability (values are validated when actions and states are constructed; an unhashable one still falls back to the dropping constructor and its warning). The union of precondition and effect keys is remembered per action list instead of being recomputed by every node on every step. Changelog for the performance pass.
✅ Code Quality Report
Quality Gates
🎉 All quality gates passed! This PR maintains high code quality standards. 📊 View detailed MFCQI breakdownRun |
This was referenced Nov 17, 2026
Merged
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.
A performance pass over the hot paths, measured before and after on the same machine (macOS-26.6.2-x86_64-i386-64bit-Mach-O 3.13.14, Intel Core i7-9750H) with the repository's pytest-benchmark suite plus two new cases. Three commits:
relevant_actions: a backward closure over the keys the goal reads and the precondition keys of actions that write relevant keys). Reachable but useless actions used to multiply the state space by every combination of the facts they set. Pruning is skipped when a relevant action has callable effects, which may read any key; MCTS keeps every action when none writes a goal key so its anytime fallback still returns a step. A* also skips copying the state for an action whose effects already hold.LazyStates,LazyHistory): every graph node rehydrates the state, and rebuilding onePlanningStateper plan step and oneActionResultper history entry on every node made a run quadratic in its length. Both sequences compare, index, slice and concatenate like the tuple and list they replace;Plan.expected_statesandGoapState["execution_history"]are now typed as sequences (changelog, Changed).PlanningState.applyand remembered planning keys.Method: baseline run of
tests/benchmarks/onmain(f91882e) with--benchmark-json, then the same suite on this branch; the two new cases were run on a detached worktree of f91882e. The two heavier distractor cases never finished a singleplan()call within 300 s on the old code (one attempt each, hard alarm), so they have no before number: after, they take 1.2 ms and 6 ms. Means from pytest-benchmark; this laptop's run-to-run noise on the same code was up to about 30 percent on the loop benchmarks, so the table is for the large changes, not the single digits. Nothing above 50 microseconds got slower.Full suite: 2171 passed, 2 skipped;
make lintclean. Changelog updated under Unreleased.