From 6beed6cb018288ec02e5762f6a7e2e74615b1af7 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Mon, 26 Oct 2026 20:47:23 -0500 Subject: [PATCH] Test two inline-cache entries inline at dynamic-tier property sites A dynamic-tier property site tested only the first entry of its cache inline and called scr_js_get_probe (or scr_js_store_probe) for anything else. A site that sees two layouts, such as object literals of one record built in two key orders, then took the out-of-line probe on every access to objects of its second layout. Sites now test the first two entries inline, own or prototype, for reads and replacing writes. The probe still answers the third and fourth entries, misses and everything that is not plain data. --- packages/compiler/src/backend/llvm/js-ic.ts | 11 +++++++---- packages/compiler/test/js-ic-emission.test.ts | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/compiler/src/backend/llvm/js-ic.ts b/packages/compiler/src/backend/llvm/js-ic.ts index dc1aeab16..dbd11c155 100644 --- a/packages/compiler/src/backend/llvm/js-ic.ts +++ b/packages/compiler/src/backend/llvm/js-ic.ts @@ -84,10 +84,13 @@ function kindIs(host: Host, d: string, kind: number, yes: string, no: string): v * inline made polymorphic reads 7-10% faster (the design prototype's W2/W3) * and monomorphic method code no faster, for 65-225 more bytes per site; * the prototype hit made method-heavy code 3-6% faster for 15-90 bytes. - * So a site tests entry 0, own or prototype, and its probe does the rest. - * (0 makes every access probe: with a runtime built with SCR_JS_VERIFY, - * that probes every access.) */ -const INLINE_WAYS: number = 1; + * Two entries cover the common two-layout site (object literals of one + * record built in two key orders): on bench:runtime's dynamic-properties + * they made the run 13% faster than one entry, and 26% faster without its + * class instances; four were no faster than two. So a site tests entries + * 0 and 1, own or prototype, and its probe does the rest. (0 makes every access probe: with a runtime + * built with SCR_JS_VERIFY, that probes every access.) */ +const INLINE_WAYS: number = 2; const INLINE_PROTO = true; /** The address of slot `slot` of layout-mode object `d`. */ diff --git a/packages/compiler/test/js-ic-emission.test.ts b/packages/compiler/test/js-ic-emission.test.ts index b350c743d..e0ad8e329 100644 --- a/packages/compiler/test/js-ic-emission.test.ts +++ b/packages/compiler/test/js-ic-emission.test.ts @@ -50,6 +50,10 @@ console.log(read(o), at(dyn([5, 6]), 1), call(o), o.n); ); expect(body(llvm, "read")).toContain("@scr_js_get_probe("); expect(body(llvm, "write")).toContain("@scr_js_store_probe("); + // Reads and writes test the first two entries inline: the second + // starts 40 bytes into the record. + for (const site of ["read", "write"]) + expect(body(llvm, site)).toMatch(/getelementptr inbounds i8, ptr @sc_js_ic_\d+, i64 40$/m); expect(body(llvm, "at")).toContain("@scr_js_keyed_probe("); expect(body(llvm, "call")).toContain("@scr_js_load_probe("); // A compound assignment stores its number result from the jsval: an