Skip to content

HermitCrab analysis: defer the per-template clone in AnalysisAffixTemplateRule (1.054x wall-clock, not a step count) #586

Open

Description

@johnml1135

AnalysisAffixTemplateRule.Apply makes an internal engine clone of the input, freezes it once per template, and runs the slot DFS on the clone. The input is already frozen at every call site and slot rules never mutate it, so the DFS can run on the input directly. Only the two emission points that can pass the input through unchanged (ApplySlots terminal, ParallelApplySlots push) need a frozen clone. The traced path keeps the eager clone, because the trace manager stamps CurrentTrace onto the words it is given. The change is on the archived branch perf/hc-optimization-archive.

Measured. Clone-discard count (Amharic): 2,505 clones created, 1,659 discarded (66%). Wall-clock A/B on 45 Sena words, min of two interleaved rounds: 1.054x overall, 1.02x to 1.08x on heavy words. No step count was recorded. Parity was checked with WordAnalysisSignature, which on Sena compares morph counts only.

What a revival must do first. Re-measure in steps or allocations rather than wall time. Check parity with a gloss, allomorph-index and syntactic-feature-structure signature, not morph counts. The saving is allocation only, so a port that already clones lazily gains nothing.

Record: https://github.com/sillsdev/machine/blob/2eba2f502338705a4d529d7034cecb6303db7f35/docs/optimizations/deferred-template-clone.md
Ledger: https://github.com/sillsdev/machine/blob/2eba2f502338705a4d529d7034cecb6303db7f35/docs/hermitcrab-optimization-ledger.md; disposition: https://github.com/sillsdev/machine/blob/2eba2f502338705a4d529d7034cecb6303db7f35/docs/hermitcrab-perf-2026-09-disposition.md
From #490 (closed).

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions