Skip to content

HermitCrab shapes: build the node map inside Shape.CopyTo's copy pass (no isolated measurement) #592

Open

Description

@johnml1135

Shape.CopyTo copies the nodes of a range, then builds the source-to-copy node map in a second pass with Zip and ToDictionary, so that annotations can be remapped. The source and destination nodes are already visited in matching order during cloning, so the loop can record the mapping as it goes. The change allocates the map on the first node of a nonempty range and fills it in the copy pass, and skips the map for an empty range. It removes one enumeration and one LINQ dictionary from each annotated shape copy. The change is on the archived branch perf/hc-optimization-archive.

Measured. Nothing in isolation. It was timed only together with shape copy-on-write and the feature-structure clone work, so no standalone ratio is claimed.

What a revival must do first. Measure it alone, in allocations per shape copy. Keep ShapeCopyToTests (empty ranges, leaf and spanning annotations, remapping, independence of the copy).

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/shape-copy-single-pass-map.md), which is being deleted:

    Build Shape.CopyTo's node map in the copy pass

    Status: retained on perf/hc-optimization-archive, not merged (Shape.CopyTo).
    Portable: yes, when a port has the same node-remapping requirement.

    Invariant

    Annotations refer to nodes in the source shape and must be remapped to the corresponding nodes in the copy.
    The source and destination nodes are already visited in matching order while cloning, so that loop can record
    the mapping directly. No second Zip/ToDictionary traversal is required. An empty source range needs no
    map; every nonempty range builds one because annotations are queried only after nodes have been copied.

    Implementation

    Shape.CopyTo allocates the map on the first node of a nonempty range and fills it as each node is cloned.
    Annotation ranges are then copied through that map exactly as before.

    Evidence

    The change removes one enumeration and one LINQ-built dictionary from each annotated shape copy. It was not
    timed independently from shape copy-on-write and feature-structure clone work, so no standalone ratio is
    claimed.

    Correctness coverage and limits

    ShapeCopyToTests covers empty ranges, leaf and spanning annotations, node/range remapping, and independence
    of the copy.
    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

    • Status
      🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions