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 feature structures: allocation-free ValueEquals for frozen flat trees (no isolated measurement) #588
Freeze marks a FeatureStruct as a flat tree when every reachable value is a SimpleFeatureValue, no value instance repeats and no nested FeatureStruct exists. FeatureStruct.ValueEquals then compares two such frozen structures by feature count, key and value, with no visited-pair set. This is equivalent to the general walk, because a flat tree cannot trigger its reentrancy or cycle guard. Shared leaves, nested structures and cycles use the general path. A test-only entry point lets randomized tests compare the two paths. The change is on the archived branch perf/hc-optimization-archive.
Measured. Nothing in isolation. The same profile that motivated traversal-state reuse put feature-structure equality and freezing at 13.7% of wall time on the heaviest Sena word. The record claims no standalone ratio.
What a revival must do first. Time it separately from the other feature-structure changes, in unification or visited-set operations avoided. Keep the randomized cross-check against the slow path (FeatureStructTreeFastPathTests, FeatureStructValueEqualsFreezeTests).
Archived from docs/hc-optimization-ledger @ 2eba2f5 (docs/optimizations/feature-struct-frozen-tree-equality.md), which is being deleted:
Allocation-free equality for frozen flat feature structures
Status: retained on perf/hc-optimization-archive, not merged (FeatureStruct.ValueEquals). Portable: yes; the proof depends on immutability and tree shape, not the CLR.
Invariant
During Freeze, a feature structure is marked as a flat tree only when every reachable value is a SimpleFeatureValue, no value instance repeats, and no nested FeatureStruct is present. Once frozen, that
fact cannot change. Comparing two such structures can never trigger the general algorithm's reentrancy or
cycle guard, so a feature-count/key/value comparison is equivalent to the general visited-pair walk.
Implementation
ValueEquals uses the direct leaf comparison only when both operands are frozen and carry the tree proof.
Every other shape—including shared leaves, nested structures, and cycles—uses the general algorithm. A
test-only slow-path entry point lets randomized tests compare both implementations on the same inputs.
Evidence
The optimization removes all visited-set work from the dominant frozen, flat case. It was observed in the
same profile that motivated traversal-state reuse, but was not isolated from the other feature-structure
changes; no standalone wall-time ratio is claimed.
Correctness coverage and limits
FeatureStructTreeFastPathTests cross-checks randomized flat structures against the slow path and exercises
false comparisons and structures that must not qualify. FeatureStructValueEqualsFreezeTests covers shared
and cyclic graphs. The full conformance-inclusive run passed 603 tests with one expected host skip.
Activity
johnml1135 commentedon Nov 7, 2026
Archived from
docs/hc-optimization-ledger@ 2eba2f5 (docs/optimizations/feature-struct-frozen-tree-equality.md), which is being deleted:Allocation-free equality for frozen flat feature structures
Status: retained on
perf/hc-optimization-archive, not merged (FeatureStruct.ValueEquals).Portable: yes; the proof depends on immutability and tree shape, not the CLR.
Invariant
During
Freeze, a feature structure is marked as a flat tree only when every reachable value is aSimpleFeatureValue, no value instance repeats, and no nestedFeatureStructis present. Once frozen, thatfact cannot change. Comparing two such structures can never trigger the general algorithm's reentrancy or
cycle guard, so a feature-count/key/value comparison is equivalent to the general visited-pair walk.
Implementation
ValueEqualsuses the direct leaf comparison only when both operands are frozen and carry the tree proof.Every other shape—including shared leaves, nested structures, and cycles—uses the general algorithm. A
test-only slow-path entry point lets randomized tests compare both implementations on the same inputs.
Evidence
The optimization removes all visited-set work from the dominant frozen, flat case. It was observed in the
same profile that motivated traversal-state reuse, but was not isolated from the other feature-structure
changes; no standalone wall-time ratio is claimed.
Correctness coverage and limits
FeatureStructTreeFastPathTestscross-checks randomized flat structures against the slow path and exercisesfalse comparisons and structures that must not qualify.
FeatureStructValueEqualsFreezeTestscovers sharedand cyclic graphs. The full conformance-inclusive run passed 603 tests with one expected host skip.