Repository navigation
clazel-js-heap: index shape lookups (faster runtime and page setup) - #305
Merged
Merged
Conversation
The parent walk in Shapes::lookup is the spec; the index of tables shared along lines of transitions must agree with it. Contract first (CLAUDE.md rule 3); the implementation and harnesses follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- JsString::from_rust_str takes ASCII straight as Latin-1, without the UTF-16 detour; from_units checks for Latin-1 before copying. - Interner stores each string once, with its hash, and searches its own open-addressing table of key ids (std's keyed SipHash, at most half full): one hash per intern, none on growth or sweep. Before, a miss hashed twice, cloned the string twice, and every growth of the HashMap rehashed every string. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shapes::lookup walked the parent chain (up to 128 shapes) on every property get, define and add; building a runtime, and a page with the WebIDL bindings, spent most of its time there. Now every shared shape names a table (shape::index) of its properties in slot order and sorted by key, shared by the shapes on one line of transitions: a child that extends its parent's table at its end appends in place, a branch copies the parent's prefix. A lookup is a binary search, meeting the contract of the previous commit (X1 to X5); the parent walk stays as the test oracle. Also: add_property no longer looks the key up before the transition (a hit needs none, and the index refuses a duplicate); transitions are a short list until there are more than eight; sweeps shorten tables to their longest live user and free unused ones. Kani: the index's table (push, lookup at any prefix, truncate) and its binary search; Index and Shapes as a whole are covered by a random-tree unit test against the parent walk, with sweeps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atiernan
temporarily deployed
to
full-verification
November 24, 2026 21:52 — with
GitHub Actions
Inactive
…test under Miri index_table_truncate took CBMC to 10 to 18 GB within a minute (after two or three pushes, truncating to any length or to one), past CI's 16 GB runner; the Verify clazel-js-heap job on #305 died of it. Table::truncate is left to the unit tests and stated as not proven. the_index_agrees_with_the_parent_walk_on_random_trees took 184 s under Miri; it now runs 2 rounds of 40 steps there, sweeping every 20 (27 s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atiernan
temporarily deployed
to
full-verification
November 25, 2026 01:35 — with
GitHub Actions
Inactive
atiernan
added a commit
that referenced
this pull request
Nov 25, 2026
A page defines about 550 attributes (940 getter and setter functions) and uses few. Miri time of a page with every interface and a one-line script: 292 s before, 192 s now (69 s with #305's heap). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atiernan
added a commit
that referenced
this pull request
Nov 25, 2026
…nts-input (#300) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes building a JS runtime and a page with the generated WebIDL bindings much cheaper. All changes are in
clazel-js-heap; nothing inclazel-js-vm's Verus code changed.Hot spots (native
sampleof debug builds)Shapes::lookupwalked the parent chain (up to 128 shapes) on every get, define and add. It took 25% of plainRuntimesetup and 66% of page setup onclaude/dom-api, mostly throughHeap::findandHeap::define.JsString::from_rust_strwent through UTF-16 and anOptioncollect, about half of runtime setup.HashMapgrowth rehashed every string.Changes (three commits)
shape/contract.rs, X1 to X5). The parent walk is the spec (spec_lookup), andtable_well_formeddefines what a well-formed table is.shape/index.rs):add_propertyno longer looks the key up before checking transitions.Internerstores each string once, with its hash, in its own open-addressing table of key ids. It still uses std's keyed SipHash, so page-chosen names can't collide on purpose. That means one hash per intern, and none on growth or sweep.Measurements
clazel-jstests/api.rsscript_host_data_comes_backRuntime::new+ realm, debugRuntime::new+ realm, releaseclaude/dom-apiwith this cherry-picked locally: Miria_page_with_the_bindings_runs_a_scriptclaude/dom-api, native page setup, debugclaude/dom-api, native page setup, releaseThe Miri times are libtest's
--report-timeon Miri's virtual clock. The Miri timings in the table come from just before the last small change (the hand-written binary search, which took about another 4% off native debug time). The dom-api numbers are a local cherry-pick; nothing was pushed to that branch.Verification: what Kani covers and what it doesn't
New harnesses in
src/proofs.rs:index_table_push_lookup: one index table after up to 3 pushes of any key below 3, with any attributes.u32key, at any prefix lengthn, equalsspec_lookupof the firstnentries, and any slot it finds is belown(X3).index_search_any: the binary search over every sorted list of up to 4 keys, of any value, against any key.Not proven by Kani:
Table::truncate, the shortening in X5. A harness for it (after 2 or 3 pushes, truncating to any length or to 1) took CBMC to 10–18 GB within a minute. It killed CI'sVerify clazel-js-heapjob on the 16 GB runner, so it was dropped.Indexas a whole: its table list,extend's choice between appending and copying, andretain's bookkeeping.Shapes: transitions and dictionaries are hash maps.Harnesses over trees of shapes through
Indexwere tried and dropped. With symbolic parents (3 or 4 shapes) they did not finish in 25+ minutes; with a fixed tree form they ran for over 3 hours and over 12 GB. That glue is covered byshape::tests::the_index_agrees_with_the_parent_walk_on_random_trees. It builds random trees, with branches, transitions past the list cutoff and sweeps closed under parents, and checks every live shape'slookupagainst the old parent walk andspec_lookup, and every table as well formed. All existing harnesses are unchanged.Checks
cargo clippy --workspace --all-targets: clean.cargo fmt --check: clean.cargo test --workspace: passed.cargo xtask check: STATIC CHECKS PASSED.cargo xtask verify --changed: not completed locally (the first run was killed during Miri; the second was stopped to chase the CI failure).cargo kani -p clazel-js-heap: all 14 harnesses pass in 492 s. The new ones:index_table_push_lookup14 s and 1.4 GB peak;index_search_any3.5 s and 0.3 GB. The run's 17 GB peak (macOS RSS) comes from the existingdense_one_op, which is unchanged from main (17.5 GB alone);gc_mark_closed_over_rootspeaks at 10.7 GB.clazel-js-heap --lib: the random-tree test is cut from 184 s to 27 s.CI's full verification has not run yet; the proof jobs need a
full-verificationapproval.Not in this PR
Removing the
#[cfg_attr(miri, ignore = "... about 290 s ...")]attributes on #300 and #297 is a follow-up, once both have merged and the per-page Miri time has been re-measured there.🤖 Generated with Claude Code