You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HermitCrab engine: share frozen syntactic feature structures on internal Word clones (about 15% of a heavy Sena profile, never isolated) #595
Internal clones of a frozen Word deep-copy its SyntacticFeatureStruct, then freeze and hash it again when building analysis keys. The change adds Word.CloneForEngine, which shares the frozen structure until a rule must mutate it. The three in-place analysis mutation sites call EnsureOwnSyntacticFeatureStruct first. A per-Morpher setting (HC_SHARE_SYNTACTIC_FS=false opts out) controls sharing. Public Word.Clone() stays a deep, mutable clone. This is sharing, not a cache. CloneForEngine and EnsureOwnSyntacticFeatureStruct are on the archived branch only.
Measured. The heaviest Sena profile attributed roughly 15% of CPU to freezing and hashing a newly cloned syntactic feature structure while building analysis keys. The five-language measurement is branch-wide, so no standalone speedup is assigned. The wall-clock figure is a profile share and is not attributed.
What a revival must do first. Time it with the toggle alone, in clones and freezes avoided. Do not use the old morph-count signature for parity. Sharing is unavailable for mutable source words.
Archived from docs/hc-optimization-ledger @ 2eba2f5 (docs/optimizations/syntactic-feature-structure-sharing.md), which is being deleted:
Copy-on-write syntactic feature structures in engine clones
Status: retained on perf/hc-optimization-archive, not merged (Word.CloneForEngine, EnsureOwnSyntacticFeatureStruct). Portable: partly; immutable sharing is general, while the ownership
plumbing is specific to this engine.
Invariant
HermitCrab freezes a Word before it becomes an input to the analysis or synthesis graph. Internal clones may
therefore share that frozen word's syntactic feature structure until a rule needs to mutate it. The public Word.Clone() contract remains a deep, mutable clone and never exposes copy-on-write sharing to callers.
Implementation
Internal engine sites use CloneForEngine(). A per-Morpher setting is copied onto new words and controls
whether those clones share a frozen syntactic feature structure. The three in-place analysis mutation sites
call EnsureOwnSyntacticFeatureStruct() before modification; assignments of a fresh structure need no guard.
The opt-out is internal and captured per Morpher, preventing one parser or test from changing another
existing parser's behavior.
Evidence
The heaviest Sena profile attributed roughly 15% of CPU to freezing and hashing a newly cloned syntactic
feature structure while constructing analysis keys. Sharing removes that repeated deep clone/freeze on the
engine path. The final five-language measurement is branch-wide rather than an isolated toggle result, so no
standalone speedup is assigned here.
Correctness coverage and limits
WordSyntacticFsSharingTests covers copy-on-write, nested/shared structures, public-clone mutability, and
isolation between morphers. The broader HermitCrab suite exercises integration behavior and passed both with
sharing enabled and with HC_SHARE_SYNTACTIC_FS=false; the full conformance-inclusive run passed 603 tests
with one expected host skip. Sharing is intentionally unavailable for mutable source words.
Activity
johnml1135 commentedon Nov 7, 2026
Archived from
docs/hc-optimization-ledger@ 2eba2f5 (docs/optimizations/syntactic-feature-structure-sharing.md), which is being deleted:Copy-on-write syntactic feature structures in engine clones
Status: retained on
perf/hc-optimization-archive, not merged (Word.CloneForEngine,EnsureOwnSyntacticFeatureStruct). Portable: partly; immutable sharing is general, while the ownershipplumbing is specific to this engine.
Invariant
HermitCrab freezes a
Wordbefore it becomes an input to the analysis or synthesis graph. Internal clones maytherefore share that frozen word's syntactic feature structure until a rule needs to mutate it. The public
Word.Clone()contract remains a deep, mutable clone and never exposes copy-on-write sharing to callers.Implementation
Internal engine sites use
CloneForEngine(). A per-Morphersetting is copied onto new words and controlswhether those clones share a frozen syntactic feature structure. The three in-place analysis mutation sites
call
EnsureOwnSyntacticFeatureStruct()before modification; assignments of a fresh structure need no guard.The opt-out is internal and captured per
Morpher, preventing one parser or test from changing anotherexisting parser's behavior.
Evidence
The heaviest Sena profile attributed roughly 15% of CPU to freezing and hashing a newly cloned syntactic
feature structure while constructing analysis keys. Sharing removes that repeated deep clone/freeze on the
engine path. The final five-language measurement is branch-wide rather than an isolated toggle result, so no
standalone speedup is assigned here.
Correctness coverage and limits
WordSyntacticFsSharingTestscovers copy-on-write, nested/shared structures, public-clone mutability, andisolation between morphers. The broader HermitCrab suite exercises integration behavior and passed both with
sharing enabled and with
HC_SHARE_SYNTACTIC_FS=false; the full conformance-inclusive run passed 603 testswith one expected host skip. Sharing is intentionally unavailable for mutable source words.