Memoize HermitCrab's sequential analysis cascade#456
Open
johnml1135 wants to merge 1 commit into
Open
Conversation
5 tasks
Adds AnalysisStateKey/AnalysisScope/Word.ReplayOnto and wires a memo table into both the mrule cascade and the affix-template battery, so repeated analysis-cascade states reached via different rule-unapplication orders are computed once and replayed rather than re-expanded. Off by default (the existing parallel cascade is unchanged); opt in via Morpher(maxDegreeOfParallelism: 1), which selects the new sequential+memo path. Ported from an archived prototype (parse-optimization-archive) with stronger verification: the acceptance gate is analysis-set equality (canonical morpheme-signature sets), not byte-identical objects, since a memo-replayed Word is not guaranteed field-for-field identical to a freshly-computed one. Verified via unit tests (key order-invariance, replay graft correctness, in-flight re-entry guard) plus corpus runs against three real grammars (Sena, Indonesian, Amharic) with zero analysis-set divergences. On a known-pathological word, sequential+memo measured 6.2x faster than the parallel default (isolated to ~6.3x attributable to the memo itself, not threading); aggregate corpus evidence and the typical-word tradeoff are in memoization.md, along with honestly-reported open gaps.
johnml1135
force-pushed
the
feature/memoization
branch
from
July 17, 2026 11:07
5c42eaa to
8f5438a
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #456 +/- ##
==========================================
+ Coverage 73.33% 73.47% +0.13%
==========================================
Files 443 446 +3
Lines 37214 37398 +184
Branches 5110 5140 +30
==========================================
+ Hits 27290 27477 +187
+ Misses 8801 8791 -10
- Partials 1123 1130 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
new Morpher(traceManager, language, maxDegreeOfParallelism: 1), which selects the new sequential+memo path.Wordisn't guaranteed field-for-field identical to a freshly-computed one, even when it represents the same analysis.See
memoization.md(added in this PR) for the full design, the key-completeness audit, and the verification methodology.Follow-up: #457 stacks a data-structure rearchitecture (array-backed, copy-on-write
Shape) on top of this branch and re-measures the same two heavy words — read that PR for whether it's worth the larger diff.Why off by default — the actual tradeoff
This is not a pure win, and the corpus evidence says so directly:
So flipping the library's default cascade mode trades typical-word latency for pathological-word latency. Whether that's the right tradeoff depends on a given corpus's word-difficulty distribution — a decision for a future PR with its own evidence, not this one.
Verification
AnalysisStateKeyorder-invariance/hash/equality,Word.ReplayOntograft correctness (including a test that specifically distinguishes "grafted the right subtree" from "grafted the wrong one" via distinct lexical entries), theInProgressin-flight re-entry guard, positive-replay-vs-unmemoized-result-set equivalence (including trail order), and an mrule/template equivalence battery against real analysis-rule content viaMorpherTests.memoization.mdrather than glossed over. (Stack RUSTIFY's array/COW rearchitecture on top of memoization #457 revisits H2 with the array-backed rearchitecture and gets a very different result.)Test plan
dotnet build Machine.slndotnet csharpier check .dotnet testacross HermitCrab, SIL.Machine, and Thot test projectsMemoCorpusVerification,[Explicit]) run manually against local Sena/Indonesian/Amharic grammars — 0 divergences on the words that completed within the timeout budgetThis change is