Skip to content

Improve the performance of LexicalLookup - #627

Merged
jtmaxwell3 merged 7 commits into
masterfrom
perf/LexicalLookup
Nov 12, 2026
Merged

jtmaxwell3 merged 7 commits into
masterfrom
perf/LexicalLookup

Conversation

@jtmaxwell3

@jtmaxwell3 jtmaxwell3 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

This improves the performance of LexicalLookup in two ways:

  1. Don't propose the siblings of root allomorphs that match the input.
  2. Skip root allomorphs that don't unify with input.SyntacticFeatureStruct.

This change is Reviewable

@jtmaxwell3
jtmaxwell3 marked this pull request as draft November 10, 2026 01:22
@codecov-commenter

codecov-commenter commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.29%. Comparing base (0cbf85f) to head (64a0250).

Files with missing lines Patch % Lines
src/SIL.Machine.Morphology.HermitCrab/Morpher.cs 90.90% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #627      +/-   ##
==========================================
- Coverage   75.33%   75.29%   -0.04%     
==========================================
  Files         454      454              
  Lines       38509    38524      +15     
  Branches     5335     5337       +2     
==========================================
- Hits        29010    29008       -2     
- Misses       8364     8377      +13     
- Partials     1135     1139       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@claude

This comment has been minimized.

@claude

This comment has been minimized.

@claude

This comment has been minimized.

@claude

claude Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor
  1. Verdict: approve.
  2. Most important: the F8 fix (src/SIL.Machine.Morphology.HermitCrab/Morpher.cs:442) moved the clone, RootAllomorph setter and Freeze back ahead of the syntactic-FS check, so rejected homographs pay for a full Word again even with tracing off. That is the cost F4 removed. It is small next to the synthesis this PR skips, and the F8 reply suggests cloning only under IsTracing.
  3. Counts: 0 Critical, 0 Important, 0 Low new. Nothing open.
  4. Ran: git diff 62d69c4a d10da372, a 20-line change, which I reviewed by hand against TraceManager.SynthesizeWord/Failed and Word.SetRootAllomorph. I did not run a separate /code-review pass. dotnet test tests/SIL.Machine.Morphology.HermitCrab.Tests passed 183 of 183. gh pr checks 627: comment hygiene passes (advisory), changes passes, and Build on ubuntu-22.04 and windows-latest are pending.
  5. Not verified: the trace tree shape comes from code reading only, and no test runs LexicalLookup with tracing on. There is still no measurement of the speedup (F3, accepted).

Public API, target framework, package, machine.py parity: None verified. LexicalLookup is internal, and HermitCrab has no machine.py counterpart.

Findings: F1 addressed, F2 addressed, F3 accepted (no benchmark), F4 addressed (cost partly reintroduced by the F8 fix, noted in F8), F5 addressed, F6 addressed, F7 addressed, F8 addressed.

Reviewed at d10da37

@jtmaxwell3
jtmaxwell3 marked this pull request as ready for review November 11, 2026 19:11
.Where(LexEntrySelector)
.Distinct()
)
foreach (RootAllomorph allomorph in SearchRootAllomorphs(input.Stratum, input.Shape))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping the siblings of matched allomorphs changes output, not just speed, and I think the new behaviour is right. With a FLEx deletion rule i -> 0 / [u,i] _ at the default Deletion Reapplications (0), entry BU with allomorphs buii and bui / _ [C], and the word bu: analysis reaches only bui, whose environment fails in synthesis. Master still parses bu because it also proposes the sibling buii; without the bui allomorph, master finds nothing either. This branch gives the same answer both ways. Please add a test that pins this and a sentence in the PR body saying sibling allomorphs are no longer proposed.

foreach (RootAllomorph allomorph in entry.Allomorphs)
if ((allomorph.Morpheme is LexEntry entry) && LexEntrySelector(entry))
{
Word newWord = input.Clone();

@johnml1135 johnml1135 Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check now uses entry.SyntacticFeatureStruct, so it can move above Clone() (and the tracing), which saves a Word per rejected candidate.

@johnml1135 johnml1135 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I compared #627 (d10da37) with master on the fieldworks-parser-conformance suite and our HC reference grammars. No parse changed.

  • Conformance suite: 145 fixture runs and 16 stress fixtures. The per-word output is byte-identical.
  • Amharic (673 words), Aweti (206), Indonesian (70), Sena (1,000) and Mbugwe (130): the same analyses for every word.

None of these words reaches the sibling-allomorph case, so this shows the change is safe on our data rather than that it never changes output. The test I asked for at Morpher.cs:438 would pin that case. Swahili and Cebuano are FieldWorks projects only, so they weren't run here.

@claude

claude Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

No new findings. Reviewed at d26dd37

@claude

claude Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

No new findings. Reviewed at 64a0250

@jtmaxwell3
jtmaxwell3 merged commit 1eae226 into master Nov 12, 2026
8 checks passed
@jtmaxwell3
jtmaxwell3 deleted the perf/LexicalLookup branch November 12, 2026 21:15
johnml1135 pushed a commit that referenced this pull request Nov 14, 2026
* Improve the performance of LexicalLookup

* Fix issues found by Claude

* Fix F1

* Fix F8

* Fix problems reported by Johnml1135

* Create new FailureReason to avoid confusion

(cherry picked from commit 1eae226)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants