镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 7006c05

Browse files
committed
perf(vm): quicken monomorphic Number sites (#734)
Publish a one-byte acquire/release adaptive state per immutable bytecode instruction after eight Number/Number observations. Stable sites bypass repeated optimizer-profile merges; any non-Number observation publishes terminal generic state, and a specialized miss executes the canonical operation exactly once before permanent dequickening. Freeze V21 Context-owned hit/miss/dequickening attribution. At 10,000 jobs, 919643 / 79982 / 164905 / 157437 executions enter the Number kernel across the Number, BigInt, polymorphic, and coercion witnesses; checksums, VM dispatches, admissions, and zero native publication remain exact. Chunk backing changes by 24 / 36 / 24 / 24 bytes respectively. Test262 arithmetic/comparison/bitwise/shift differential: 802 -> 802 passes across 21 subtrees, 0 flips. Full Debug units: 1870 passed, 1 skipped, 0 failed/leaked. Full TSan units: 1868 passed, 2 skipped, 0 failed/leaked; the added all-operator differential also passes focused TSan. Default and TSan threadfuzz each pass 400 seeded programs with 0 failures. Benchmark harness, 39/39 matrix drift tests, quickening inventory/self-test, 277-file link audit, and 50-page docs manifest pass. Exact-parent timing is intentionally not published from the contended host; #734 remains open for a quiet AC reference run. Refs #734, #498, #461, #659.
1 parent 7d69d61 commit 7006c05

14 files changed

Lines changed: 641 additions & 81 deletions

‎bench/comparison_zig_js.zig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,13 @@ fn printTierAttributionRow(
442442
const metric: js.ExecutionTierMetric = @fromBackingInt(@intCast(field_value));
443443
try writer.print("\"{s}\":{d}", .{ name, snapshot.execution.count(metric) });
444444
}
445+
try writer.writeAll("},\"quick_binary\":{");
446+
const quick_binary_info = @typeInfo(js.QuickBinaryMetric).@"enum";
447+
inline for (quick_binary_info.field_names, quick_binary_info.field_values, 0..) |name, field_value, index| {
448+
if (index != 0) try writer.writeByte(',');
449+
const metric: js.QuickBinaryMetric = @fromBackingInt(@intCast(field_value));
450+
try writer.print("\"{s}\":{d}", .{ name, snapshot.quick_binary.count(metric) });
451+
}
445452
try writer.writeAll("},\"timing\":{");
446453
inline for (comptime std.meta.fieldNames(@TypeOf(snapshot.timing)), 0..) |name, index| {
447454
if (index != 0) try writer.writeByte(',');

‎docs/.data/bunpress-output-v1.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
},
4646
{
4747
"path": "advanced/vm-quickening/index.html",
48-
"bytes": 224271,
49-
"sha256": "a55b12cf866c0b98e064736a78ea0ebbbcbf717fbe7a63aa2ffc5888f5b17578"
48+
"bytes": 224376,
49+
"sha256": "68c580a37530cb5c1fac7fddb7d25ac1ef95d550a4832d690b47a6bbb5deeca6"
5050
},
5151
{
5252
"path": "api/index.html",
@@ -65,8 +65,8 @@
6565
},
6666
{
6767
"path": "benchmarks/index.html",
68-
"bytes": 407473,
69-
"sha256": "d8d4ecc69347095d5ff1b34eb1781d7d652e81a641a857c7dc37347e0f500fe1"
68+
"bytes": 407596,
69+
"sha256": "db22d98127097d3b873fbcf7c25895428061e335011fbcea1c1cec05e42d195c"
7070
},
7171
{
7272
"path": "c-api/README/index.html",
@@ -181,7 +181,7 @@
181181
{
182182
"path": "search-index.json",
183183
"bytes": 262467,
184-
"sha256": "f4ec54378451b978d37771834e603be252d40ff3bfa61e3249656980f3135dd2"
184+
"sha256": "d6fa9e3a6a7b91d07ad436e17e628a6e3fa101ce4cf06af42589ee33ff2051d5"
185185
},
186186
{
187187
"path": "sitemap.xml",
@@ -274,5 +274,5 @@
274274
"sha256": "c08b66f5315fb31e8adbd70e372ad0895adc21f70ae2212a6b848ffeabb974ea"
275275
}
276276
],
277-
"tree_sha256": "1009c3c4d4da820a08448f098937f122cc75ff126322e751c3dce7bf518ca7ee"
277+
"tree_sha256": "36cc07908b02083be40e3f9fb7f22d0b4111d95a53f46ed4b2f4076cddde4258"
278278
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"schema_version": 21,
3+
"matrix_id": "zig-js-representative-v21",
4+
"status": "frozen",
5+
"frozen_date": "2026-08-23",
6+
"owner_issue": 734,
7+
"history_policy": "This version hash-inherits every V20 scored workload, mode, job count, checksum, timing boundary, engine-availability ruling, acceptance decision, attribution metric, external-suite boundary, exact-parent contract, and publication boundary. It retains the V20 zig-js-only no-JIT required-bytecode rows, re-pins their runner, and adds exact Context-owned adaptive-binary attribution. No historical scored or accepted report is rewritten. Any later workload, option, checksum, mode, runner, quickening contract, or acceptance change creates another version.",
8+
"parent": {
9+
"matrix_id": "zig-js-representative-v20",
10+
"path": "docs/.data/representative-benchmark-matrix-v20.json",
11+
"sha256": "9f7f2bee6ad444fb7b0a42318ad6915ffa4b6ce4684e68bffdd2e328b9a19341",
12+
"inherit": [
13+
"compatibility_panel",
14+
"engines",
15+
"lanes",
16+
"protocol",
17+
"modes",
18+
"acceptance",
19+
"required_families",
20+
"implemented_families",
21+
"deferred_families",
22+
"additional_panels",
23+
"tier_attribution",
24+
"pending_metric_panels",
25+
"completed_metric_panels",
26+
"exact_parent_integration"
27+
]
28+
},
29+
"change": "Re-pins the comparison runner and adds exact hit/miss/dequickening attribution for the non-scored V20 required-bytecode/no-JIT arithmetic profile; every scored field remains unchanged.",
30+
"context_lifecycle_integration": {
31+
"issue": 661,
32+
"status": "integrated_non_scored_profile",
33+
"mode": "context_lifecycle",
34+
"engines": ["zig-js"],
35+
"lanes": [1],
36+
"scenarios": ["context_no_evaluation", "context_first_source", "context_first_module", "context_full_feature"],
37+
"profile": {
38+
"path": "docs/.data/context-lifecycle-profile-v1.json",
39+
"sha256": "3286810faef598fc62ce68f8a56825de48d749a7ae4778df270afd890780c6f2"
40+
},
41+
"runner": {
42+
"path": "bench/comparison_zig_js.zig",
43+
"sha256": "7d94d54516ee2eb64b3f054c4599f5d0bb3b42fcb71ea4f162478fc8b3450087"
44+
},
45+
"telemetry": ["create_ns", "work_ns", "destroy_ns", "cpu_user_ns", "cpu_system_ns", "baseline_rss_bytes", "max_live_rss_bytes", "post_destroy_rss_bytes", "retained_delta_bytes", "peak_rss_bytes", "rss_checkpoints", "gc_finalizer_stats"],
46+
"publication_boundary": "This remains the V19 zig-js-only cold lifecycle profile. V21 changes only the runner hash to expose Context-owned quick-binary attribution in separate tier rows; no lifecycle option, scenario, checksum, telemetry, or evidence ruling changes."
47+
},
48+
"no_jit_integration": {
49+
"issue": 734,
50+
"status": "integrated_non_scored_profile",
51+
"engines": ["zig-js"],
52+
"modes": ["single_no_jit", "attribution_no_jit"],
53+
"lanes": [1],
54+
"context_options": {
55+
"enable_jit": false,
56+
"bytecode_execution_mode": "required"
57+
},
58+
"source": {
59+
"path": "bench/vm_arithmetic_comparison.js",
60+
"sha256": "970e58bec6ab9978335e6f908219bf23154c9ec9ff96ccefc6a94f2917d77fa8"
61+
},
62+
"runner": {
63+
"path": "bench/comparison_zig_js.zig",
64+
"sha256": "7d94d54516ee2eb64b3f054c4599f5d0bb3b42fcb71ea4f162478fc8b3450087"
65+
},
66+
"workloads": [
67+
{"id": "representative_vm_arithmetic_number", "role": "stable_number", "jobs": {"quick": 100, "full": 10000}, "checksums": {"quick": 606036, "full": 5236590351}},
68+
{"id": "representative_vm_arithmetic_bigint", "role": "stable_bigint_control", "jobs": {"quick": 100, "full": 10000}, "checksums": {"quick": 5412345, "full": 630334997}},
69+
{"id": "representative_vm_arithmetic_polymorphic", "role": "number_string_bigint_object_control", "jobs": {"quick": 100, "full": 10000}, "checksums": {"quick": 29422, "full": 28806122}},
70+
{"id": "representative_vm_arithmetic_coercion", "role": "effect_and_exception_control", "jobs": {"quick": 100, "full": 10000}, "checksums": {"quick": 101766, "full": 10176362}}
71+
],
72+
"attribution": {
73+
"tree_walker_entries": 0,
74+
"baseline_publications": 0,
75+
"optimizer_publications": 0,
76+
"generated_code_bytes": 0,
77+
"required_nonzero": ["vm_entries", "vm_dispatches", "program_compiled", "template_plain_compiled"]
78+
},
79+
"quick_binary": {
80+
"issue": 734,
81+
"number_observation_threshold": 8,
82+
"state_bytes_per_instruction": 1,
83+
"generic_is_terminal": true,
84+
"specialized_miss_executes_ordinary_once": true,
85+
"counters": ["number_hits", "number_misses", "dequickenings"],
86+
"stable_number": {"number_hits": "nonzero", "number_misses": 0, "dequickenings": 0},
87+
"full_attribution": [
88+
{"workload": "representative_vm_arithmetic_number", "vm_entries": 28, "vm_dispatches": 3020460, "number_hits": 919643, "number_misses": 0, "dequickenings": 0},
89+
{"workload": "representative_vm_arithmetic_bigint", "vm_entries": 28, "vm_dispatches": 900541, "number_hits": 79982, "number_misses": 0, "dequickenings": 0},
90+
{"workload": "representative_vm_arithmetic_polymorphic", "vm_entries": 28, "vm_dispatches": 1180600, "number_hits": 164905, "number_misses": 0, "dequickenings": 0},
91+
{"workload": "representative_vm_arithmetic_coercion", "vm_entries": 28, "vm_dispatches": 810659, "number_hits": 157437, "number_misses": 0, "dequickenings": 0}
92+
],
93+
"publication_boundary": "Counters are exact Context-owned atomics read only in the separate attribution mode. Stable Number rows must hit without misses; per-site unit tests prove polymorphic/coercive sites become terminal generic and that one specialized miss dequickens without replay. Exact-parent timing remains a separate artifact."
94+
},
95+
"timed_boundary": "One invocation in one persistent production Context after ten reduced-work warmups; source/configuration, warmup, Context creation/destruction, attribution, and hardware snapshots are outside elapsed_ns.",
96+
"publication_boundary": "These rows freeze logical work and prove required-bytecode/no-native execution. Battery diagnostics and structural attribution are not performance evidence. A speed claim requires exact-parent, order-balanced, quiet-reference AC samples with stable required counters and unchanged controls."
97+
}
98+
}

‎docs/.data/vm-quickening-inventory-v1.json‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,28 @@
325325
],
326326
"metrics": ["quick_observable_recurrence_hits"]
327327
},
328+
{
329+
"id": "binary-arithmetic-site",
330+
"title": "Adaptive Number binary dispatch",
331+
"classification": "general_adaptive",
332+
"implementation_kind": "adaptive_site_cache",
333+
"coverage_status": "covered_guarded",
334+
"surfaces": ["add/subtract/multiply/divide/remainder/power", "relational and equality comparisons", "bitwise operations and shifts"],
335+
"guards": ["exact Number representation for both operands", "eight successful Number observations", "in remains generic because its RHS must be Object"],
336+
"miss_behavior": ["record both changed operand kinds", "atomically publish terminal generic state", "execute the canonical operation exactly once without replaying coercion or exceptions"],
337+
"metadata_lifetime": "One byte-sized atomic QuickBinaryState per immutable bytecode instruction in the owning Chunk arena; non-binary slots stay cold and teardown requires no separate reclamation.",
338+
"no_gil_synchronization": "Observation/publication/dequickening use acquire-release atomics; generic is terminal under every interleaving and Context-owned attribution counters are atomic.",
339+
"observable_steps_debugger": "A hit replaces only one already-counted binary opcode. Debugger, watchdog, handler/finally, OOM, and moving-GC boundaries remain in the ordinary dispatch loop; a miss performs no coercion before canonical fallback.",
340+
"source_anchors": [
341+
{"path": "src/bytecode.zig", "text": "pub const QuickBinaryState = struct {"},
342+
{"path": "src/vm.zig", "text": "inline fn quickNumberBinary("}
343+
],
344+
"test_anchors": [
345+
{"path": "src/bytecode.zig", "text": "test \"quick binary generic publication wins concurrent Number observations\""},
346+
{"path": "src/context.zig", "text": "test \"Number-specialized misses dequicken once without replaying coercion or throws\""}
347+
],
348+
"metrics": ["quick_binary_number_hits", "quick_binary_number_misses", "quick_binary_dequickenings"]
349+
},
328350
{
329351
"id": "native-direct-call",
330352
"title": "Guarded native numeric-leaf call entry",
@@ -368,13 +390,6 @@
368390
"remaining": ["general JS call and construct specialization", "variadic/spread calls", "async/generator calls", "polymorphic call-site linking across arbitrary callees"],
369391
"fallback": "ordinary activation/trampoline, callValue, invokeMethod, or construct dispatch"
370392
},
371-
{
372-
"id": "arithmetic-dispatch",
373-
"status": "unsupported",
374-
"covered_by": [],
375-
"remaining": ["general opcode quickening across Number/BigInt/string coercions", "site rewriting or adaptive specialized arithmetic opcodes", "dequickening after representation changes"],
376-
"fallback": "ordinary arithmetic bytecodes and canonical ECMAScript coercion helpers"
377-
},
378393
{
379394
"id": "control-dispatch",
380395
"status": "unsupported",
@@ -417,6 +432,7 @@
417432
},
418433
"chunk_metadata_fields": [
419434
"quick_property_plans",
435+
"quick_binary_states",
420436
"quick_property_kernel_plans",
421437
"quick_array_plans",
422438
"quick_call_plans",
@@ -430,6 +446,9 @@
430446
"quick_array_loop_candidate"
431447
],
432448
"observability_counters": [
449+
"quick_binary_number_hits",
450+
"quick_binary_number_misses",
451+
"quick_binary_dequickenings",
433452
"quick_property_update_hits",
434453
"quick_property_loop_tail_hits",
435454
"quick_property_specialized_hits",

‎docs/advanced/vm-quickening.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The complete machine contract—including every guard, miss/dequickening rule, m
1515

1616
| classification | meaning | current families |
1717
| --- | --- | ---: |
18-
| `general_adaptive` | Site/opcode behavior selected from runtime identity, shape, or representation guards rather than a whole benchmark-shaped body. | 5 |
18+
| `general_adaptive` | Site/opcode behavior selected from runtime identity, shape, or representation guards rather than a whole benchmark-shaped body. | 6 |
1919
| `bounded_structural` | A bounded expression/trace decoder with explicit accepted operations and size limits. | 2 |
2020
| `legacy_narrow` | An exact bytecode-pattern kernel. It is useful implementation history, not broad dispatch-family coverage. | 9 |
2121

@@ -38,6 +38,7 @@ The complete machine contract—including every guard, miss/dequickening rule, m
3838
| `reusable-immediate-closure` | `legacy_narrow` | checkpoint-spanning fallback iterations of the exact closure-template numeric call loop | allocate a fresh closure through makeClosure; never reuse when identity could escape or be observed |
3939
| `numeric-recurrence` | `legacy_narrow` | one exact pure two-branch additive self-recurrence bytecode body | perform the ordinary recursive JS call; cache an explicit unsupported recurrence plan |
4040
| `observable-numeric-recurrence` | `legacy_narrow` | one exact additive self-recurrence with an observable counter property update | perform ordinary recursive calls/property operations; unsupported shapes use the explicit recurrence-plan tag |
41+
| `binary-arithmetic-site` | `general_adaptive` | add/subtract/multiply/divide/remainder/power; relational and equality comparisons; bitwise operations and shifts | record both changed operand kinds; atomically publish terminal generic state; execute the canonical operation exactly once without replaying coercion or exceptions |
4142
| `native-direct-call` | `general_adaptive` | ordinary call of a ready baseline/optimizing numeric leaf without heap activation construction | build/run the ordinary VM activation or generic call; a managed native miss/deoptimization never becomes a completed direct call |
4243

4344
Every legacy pattern above remains labeled `legacy_narrow`; none is used as evidence that its broader property, index, call, arithmetic, control, or allocation family is covered.
@@ -49,10 +50,9 @@ Every legacy pattern above remains labeled `legacy_narrow`; none is used as evid
4950
| `property-dispatch` | general megamorphic named access; arbitrary prototype depth; accessor/proxy/exotic get and set; general compound/update operations | ordinary get_prop/set_prop bytecode and the full interpreter property algorithms |
5051
| `index-dispatch` | sparse and holey arrays; prototype-indexed properties; typed arrays and arguments objects; dynamic ToPropertyKey and proxy/accessor cases | ordinary get_index/set_index bytecode with full ToPropertyKey and property semantics |
5152
| `call-dispatch` | general JS call and construct specialization; variadic/spread calls; async/generator calls; polymorphic call-site linking across arbitrary callees | ordinary activation/trampoline, callValue, invokeMethod, or construct dispatch |
52-
| `arithmetic-dispatch` | general opcode quickening across Number/BigInt/string coercions; site rewriting or adaptive specialized arithmetic opcodes; dequickening after representation changes | ordinary arithmetic bytecodes and canonical ECMAScript coercion helpers |
5353
| `control-dispatch` | general superinstructions; adaptive branch/control-flow fusion; exception/finally-aware trace formation; debugger-safe dequickening at every statement boundary | ordinary branch, completion, handler, and checkpoint bytecodes |
5454
| `allocation-dispatch` | general object/array/closure allocation specialization; arbitrary literal layouts; escape analysis and scalar replacement; general GC-safe allocation sinking | ordinary new_object/new_array/make_closure/literal bytecodes and allocator/GC paths |
5555

5656
## Drift gate
5757

58-
The validator binds this inventory to 6 plan types, 14 tagged quickening types, 8 chunk metadata fields, 2 structural-candidate flags, and 30 test observability counters. Missing or duplicate identities, missing source/test anchors, unknown status values, and any legacy kernel relabeled as general all fail closed.
58+
The validator binds this inventory to 6 plan types, 14 tagged quickening types, 9 chunk metadata fields, 2 structural-candidate flags, and 33 test observability counters. Missing or duplicate identities, missing source/test anchors, unknown status values, and any legacy kernel relabeled as general all fail closed.

0 commit comments

Comments
 (0)