Repository navigation
perf(hermitcrab): share trailing analysis template slot batches - #546
johnml1135 wants to merge 6 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #546 +/- ##
==========================================
+ Coverage 75.53% 75.65% +0.12%
==========================================
Files 455 456 +1
Lines 38933 39051 +118
Branches 5428 5452 +24
==========================================
+ Hits 29407 29543 +136
+ Misses 8376 8367 -9
+ Partials 1150 1141 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d6f481e to
5ed55e0
Compare
This comment has been minimized.
This comment has been minimized.
…round AnalysisScope.TemplateMemo no longer wraps the battery on master, so the statement that #546 composes with it is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…round AnalysisScope.TemplateMemo no longer wraps the battery on master, so the statement that #546 composes with it is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5ed55e0 to
536686d
Compare
R1, R2, R5 and T1 are kept with their net-of-own-cost numbers in steps, R4 is a recorded dead end, R6 is unbuilt, R3 and R1 on #546 are in progress. Adds ledger rows 38-46. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rows 43 and 44 move from in progress to done. R1 on #546 is draft PR #577 (commit bbb81a0, shadow 0 violations); R3 ordered look-ahead is draft PR #576 (shadow 0 violations). Adds the round-doc section for both and the PanGloss port issues (sillsdev/PanGloss #65, #66). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
536686d to
17a6894
Compare
|
I don't know if it is worth doing now, but we could make this work even with tracing on if we added BeginUnapplyTemplate (with a null template argument) to AnalysisAffixTemplatesRule.Apply and suppressed the call to BeginUnapplyTemplate when it calls AnalysisAffixTemplateRule.CanApply. We would also need calls to EndUnapplyTemplate with the appropriate template argument at the termination of each template. This would match how AnalysisAffixTemplateRule currently works, since each call to AnalysisAffixTemplateRule.Apply emits one BeginUnapplyTemplate and one or more EndUnapplyTemplates (because of multiple rules and optional slots). These form a tree in the trace. The call to AnalysisAffixTemplatesRule would also form a tree in the trace, but its root covers all of the templates instead of just one. The only change to the UI would be that the user wouldn't know which templates are being considered until the end. On the other hand, the trace would be simpler because there would be one node in the trace for all of the templates rather than one node for each of the templates. If we do this, then we might not need AnalysisAffixTemplateRule anymore, and always use AnalysisAffixTemplatesRule, even when there are no shared slots. What do you think? |
I like it, and folding |
jtmaxwell3
left a comment
There was a problem hiding this comment.
I'm willing to postpone changing how tracing works for another PR.
…k guard, avoid per-node closures The shared walk is only taken when MaxAlternatives is 0, so its limit check could never fire; the guard comment now names all five fallback conditions; Walk checks admitted templates with a loop instead of a capturing lambda. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#522 removed AnalysisStateKey along with the analysis-cascade memo and kept the same identity as AnalysisStratumRule.AnalysisMergeKey, so the shared-walk equivalence test now compares outputs under that key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The shared walk runs the slots itself and does not evaluate the look-ahead from #575, so it falls back to the per-template walk unless the look-ahead is Off. The look-ahead is On by default, so this keeps parse behaviour unchanged; running the look-ahead inside the shared walk is #577. Shared-walk tests pin the look-ahead Off so they still exercise the shared walk, and a new test checks that On and Shadow keep the per-template walk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since 98d902a only partial rules, not partial lexical entries, turn final-template pruning off, so the test language now prunes NonTemplate inputs at final templates and the comparison sees 741-984 words per variant instead of over 1000. The outputs still match; the floor only guards against a vacuous comparison. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17a6894 to
c94ea0e
Compare
Public API, target framework, package, machine.py parity: None verified. Findings: F1 addressed, F2 addressed, F3 addressed, F4 addressed, F5 new. Reviewed at c94ea0e |
Start here:
src/SIL.Machine.Morphology.HermitCrab/AnalysisAffixTemplatesRule.cs-- the slot trie and the shared walk;AnalysisStratumRulenow builds it instead of a plainRuleBatch.Status: open since 2026-10-22, rebased onto master after #522 (merged). CI green. Review of the design is what it waits on.
FieldWorks consumer: FLEx's parser worker adopts this through
ParseWordson a degree-1 Morpher, tracked in LT-22885.What it does. Templates whose trailing slots are identical (same rule objects, same order, same optionality) now run each shared slot batch once per battery call instead of once per template. Output order and first-seen words per template are unchanged. On a rebased-head benchmark the shared walk cut slot batches by 33.1% (Sena sample) and 21.9% (Mbugwe sample).
The unknown you arrive with: does a shared walk lose or reorder parses? No. Each trie edge is the same ordered rules and optionality beneath the same preceding slots, so every template under it reaches the edge with the word its own walk would. Outputs are still unioned per template, in template order, so the same representatives reach analysis folding. The question worth your time is the guard list, not the walk.
Where to look
SharedWalkMatchesPerTemplateWalkInOrder(4 grammar variants) compares the shared walk with the per-templateRuleBatch, by orderedWordequality and byAnalysisStratumRule.AnalysisMergeKeysequence.UntracedBatteryRunsSharedSlotBatchOncepins two identical tails to one execution, and the next call executing again.Applyguard):TracedAndParallelBatteriesKeepPerTemplateWalk,SharedWalkPreservesBatteryAlternativeLimit,AlternativeLimitStopsBeforeLaterTemplateAdmission,ChangedSlotOptionalityPreservesPerTemplateWalk.AnalysisAffixTemplateRule.CanApplyis now split out so the trie checks each template once.Not here. The shared walk runs only at
Morpher.MaxDegreeOfParallelism == 1and only with required-slot look-ahead off (PruneRequiredSlots = false,RequiredSlotLookahead == Off). Look-ahead defaults to On (Morpher.cs), so at default settings the shared walk does not run, at any degree: theApplyguard falls back to the per-template walk. The look-ahead is a per-template walk concern, so the guard keeps the original walk whenever it runs; combining the two is not attempted here. Making them compatible is separate work. A defaultMorpher(degree 0) never takes it: the guard sends every degree-0 call to the originalParallelApplySlotspath, so this PR does not speed up default callers. That is deliberate: sharing the layered parallel queue needs its own design. The planned route is word-level parallelism, not intra-word: #582 (Morpher.ParseWords, open) requires a degree-1 Morpher, runs each word on the sequential degree-1 path and parses 4 words at once by default, so batch parsing gets the shared walk once look-ahead is also off. #546 itself stays degree 1. FieldWorks HCParser and the HermitCrab tool use the default degree and would need to move toParseWordsto benefit. Also not here: tracing, finiteMaxAlternatives, custom compiled templates, changed slot optionality. Full-corpus parity is not verified.Stack and verification. Independent of the other open HermitCrab PRs; #577 stacks on this. Ran earlier at an older head: HermitCrab test project,
git diff --check, restore and CSharpier. Not run:./local_check.shbuild step (native SentencePiece build needscmake, absent locally; CI builds pass). The conformance suite (#480 head) was not rerun after the rebase; its older results are in Evidence.Next: review the guard list in
AnalysisAffixTemplatesRule.Apply, then approve or name a missing fallback.Reading this a year from now -- start here
This change shares trailing slot batches across affix templates inside one battery call. It is separate from #490's battery-level memo, which #522 removed: that memo cut battery invocations, this cuts repeated slot batches inside one invocation. The precedent is sillsdev/PanGloss ledger entry 095,
docs/divergences/095-shared-template-slot-batches.md, and itsstratum.rsslot trie.Decisions and why
ParallelApplySlots); sharing it needs its own design. Parallelism across words (Add bounded batch parsing to HermitCrab #582) is the planned route; it requires a degree-1 Morpher.MaxAlternativesuses the original walk to keep early termination and per-template admission.Parity argument
Recursing through batch outputs in their existing order, then taking the optional unchanged-word continuation, preserves each template's depth-first emission sequence and admits or loses no parses. Each template keeps its own output set, unioned in template order with the existing comparer, so first-seen representatives and ordered words reach deduplication and analysis folding unchanged.
Evidence
Measured at an earlier head, before #522 removed the memo, so absolute batch counts predate the rebase. Single-threaded, sharing disabled versus enabled, new analysis scope per parse, temporary counters only in the output-directory build. The two later figures in the pitch come from a benchmark on the rebased head.
All completed segmentable pairs had identical morpheme-ID/surface signature lists after ordinal sorting, including multiplicity: zero differences, zero errors. Sena had 28 matching invalid-shape outcomes and no capped pairs; Mbugwe excluded 61 pairs that hit a two-second watchdog in either mode. Samples are evenly spaced nonempty rows from each word list. No corpus words, parse examples or grammar contents are included.
Conformance (#480 head, 60 fixtures,
--include-pathological, older head): this branch and the unchanged base both failed 2. The requested 60/60 baseline could not be reproduced: both fail traced-rule attribution inboundary-leftover-in-narrowing-lhs-strrep, anddeep-optional-affix-nestingcrosses its 15-second budget, using the original walk because it has no shared slot tails.Local runs used WSL
~/.dotnet, cached NuGet packages and bounded workers, no network../local_check.shand--agent-strictfailed only at the native SentencePiece build (missingcmake); restore, CSharpier and the comment scan passed.🤖 Generated with Claude Code
This change is