ReviewOS

zig-utils/zig-js

Shapes: scan shallow fixed-field records once

#595
Closed chris opened this 9 days ago ·
9 days ago

Parent: #475 Follows: #594

Profile

After #594, a fresh 100,000-job representative_temporal sample makes fixed-field duration snapshots the dominant remaining native leaf: mem.eqlBytes (240 top-of-stack samples), Shape.lookupState (202), and namedOwnDataValuesSnapshot (55). The current safe snapshot still performs one full Shape lookup per requested name, so a one-property duration literal and %Object.prototype% repeatedly walk the same immutable shallow chains.

Scope

  • Add a bounded, allocation-free fixed-field snapshot primitive that scans a shallow immutable Shape chain once and classifies only the requested names.
  • Preserve newest-operation/deletion semantics, accessor rejection, one-lock value publication, and the lock-free all-absent linearization point.
  • Use a compile-time exact classifier so attacker-controlled names do not enter a hash shortcut or collision-prone cache.
  • Fall back before observable work for deep/dictionary-shaped objects; add no unbounded or process-global cache.

Acceptance

  • Tests cover present, absent, deleted/re-added, accessor, and fallback shapes.
  • Focused normal and TSan gates pass with zero leaks/races.
  • Core and Intl402 Temporal subtrees remain exact.
  • Exact-parent base/variant measurements retain matching checksums and show a stable improvement.
  • Full sharded units pass.

No-workaround rules

No immutable-user-object assumption, skipped getter, stale slot cache, hash-only name identity, unsynchronized slot read, unbounded shape cache, or changed fallback semantics.

9 days ago

Implementation and validation are complete. Shallow Shapes now resolve a compile-time-classified fixed field set with one newest-to-oldest walk; deletion state wins over older slots, accessors and depth >32 decline before observable work, and present values are revalidated/copied under one property lock. The exact classifier performs byte equality after length/prefix routing and an invalid internal index safely declines even in release builds.

Exact-parent (b795eeb2) 21-pair order-balanced 1,000-job medians, matching checksums:

  • representative_temporal: 112.841 ms -> 93.879 ms (-16.80%)
  • representative_temporal_variant: 112.408 ms -> 92.460 ms (-17.75%)

100-job attribution remains exact at checksum 202578610542, 90,315 property locks, 47,485 named snapshots, 80,824 backing allocations, and 47,788 GC cells; CPU attribution was 52.817+4.243 ms parent versus 48.134+3.943 ms candidate.

Validation:

  • Shape focused normal + TSan: 1/1 each, zero leaks/races
  • Temporal observability normal + TSan: 1/1 each, zero leaks/races
  • test/built-ins/Temporal: 4,603/4,603
  • test/intl402/Temporal: 2,029/2,029
  • final-source full units: 1,709 passed, 1 skipped, 0 failed, 0 leaked
9 days ago

Landed on main in 6be183d3. The commit includes the bounded Shape scan, safe release fallback, deletion/depth regression, exact-parent measurements, and full validation above.

Sign in to comment on this issue.