Skip to content

Change Add to PriorityUnion - #494

Draft
jtmaxwell3 wants to merge 1 commit into
masterfrom
change-add-to-priority-union
Draft

Change Add to PriorityUnion#494
jtmaxwell3 wants to merge 1 commit into
masterfrom
change-add-to-priority-union

Conversation

@jtmaxwell3

@jtmaxwell3jtmaxwell3 commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

I fixed a performance bug by changing AnalysisAffixProcessRule.Apply to use PriorityUnion instead of Add. Add acts like Union, PriorityUnion is more restrictive. Also, SynthesisAffixProcessRule uses PriorityUnion instead of Add in the other direction, so this makes AnalysisAffixProcessRule more parallel to SynthesisAffixProcessRule.

If I have a sequence of derivation rules that change the category like [CAT:A] => [CAT:B], [CAT:B] => [CAT:A], followed by [CAT:B] => [CAT:C], then the syntactic feature structure of the input of the third rule will be [CAT:{A, B}] if I use Add, and the third rule will not be filtered when it checks whether the input can unify with [CAT:B]. If I use PriorityUnion, then the syntactic feature structure of the input of the third rule will be [CAT:A], and the third rule will be filtered when it checks whether the input can unify with [CAT:B].

This performance bug only shows up when there are at least three derivational affixes. But words that are slow to parse try many long sequences of derivational affixes. Filtering these long sequences can make a big difference.


This change is Reviewable

@jtmaxwell3
jtmaxwell3 marked this pull request as draft September 4, 2026 15:37

@ddaspitddaspit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be great if you could add a unit test to capture scenario you laid out.

@ddaspit reviewed 1 file and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on jtmaxwell3).


src/SIL.Machine.Morphology.HermitCrab/MorphologicalRules/AnalysisAffixProcessRule.cs line 59 at r1 (raw file):

 {
if (!_rule.RequiredSyntacticFeatureStruct.IsEmpty)
outWord.SyntacticFeatureStruct.PriorityUnion(_rule.RequiredSyntacticFeatureStruct);

This change should also apply to compounding rules as well.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@jtmaxwell3@ddaspit