Skip to content

HermitCrab feature structures: skip the clone map for frozen flat trees (no isolated measurement) #587

Open

Description

@johnml1135

FeatureStruct.Clone builds an old-to-new copies map on every clone. A frozen structure marked as a flat tree has no aliases or cycles below its root, so a top-level clone cannot meet the same value twice and needs no map. The change skips the map in that case. Other clones borrow a per-thread map, clear it in finally, and use a fresh map when reentered. The internal recursive constructor always uses the caller's map. This is a per-thread pooled collection, not a cross-parse cache. The change is on the archived branch perf/hc-optimization-archive.

Measured. Nothing in isolation. It was timed only as part of the package, so the record makes no speed claim.

What a revival must do first. Measure it alone, in allocations or dictionary operations avoided per clone. Keep FeatureStructCloneTests (aliases, cycles, reentrancy, a tree embedded in a shared graph) with it.

Record: see the archived write-up below
Ledger: #490 (comment); disposition: #490 (comment)
From #490 (closed).

Activity

  1. johnml1135 commented on Nov 7, 2026

    @johnml1135
    CollaboratorAuthor

    Archived from docs/hc-optimization-ledger @ 2eba2f5 (docs/optimizations/feature-struct-frozen-tree-clone.md), which is being deleted:

    Reuse or skip the feature-structure clone map

    Status: retained on perf/hc-optimization-archive, not merged (FeatureStruct.Clone).
    Portable: yes; the specific pool is .NET-oriented, while the tree proof is general.

    Invariant

    A frozen structure marked as a flat tree has no aliases or cycles to preserve below its root. Its top-level
    clone therefore cannot encounter the same value twice, so the old-to-new copies map has no semantic work to
    do. Recursive cloning inside another graph must still use the caller's map even when the child itself looks
    tree-shaped, because the parent graph may refer to that child elsewhere.

    Implementation

    A top-level clone skips the map for a proven frozen flat tree. General clones borrow a per-thread map, clear
    it in finally, and fall back to an independent map for reentrant calls. The internal recursive constructor
    always honors the caller-provided map.

    Evidence

    This removes dictionary creation and lookup from the common clone case. It travelled with the broader clone
    allocation work and was not timed independently, so the record deliberately makes no isolated speed claim.

    Correctness coverage and limits

    FeatureStructCloneTests covers alias preservation, cycles, reentrant cloning, and the distinction between a
    top-level tree and a tree embedded in a shared graph. The complete conformance-inclusive run passed 603 tests
    with one expected host-privilege skip.

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions