Repository navigation
Conversation
tools/string-bench measures string creation, concatenation, equality, search, charCodeAt, split/join, slicing, number/string conversion, template literals, string-keyed Maps, UTF-8 coding and string structured clone as typed code, plus toUpperCase and JSON through the general runtime, each in-process against the same text under Node 26.13.1. The harness is PR #17's typed-bench protocol (paired, rotated rounds under LLDB) with suites and a per-engine codec module. TwoByte kernels repeat kernels over text with code units above 0xFF. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qard
marked this pull request as draft
November 23, 2026 04:28
Growing the 1 MiB text with += made the setup quadratic in Tint, so the clone kernels measured concatenation rather than the clone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Node's structuredClone returns a primitive string without copying it (about 4 ns), so the Node side now round-trips through node:v8's serialize/deserialize, the serializer Worker messages use. Scales are recalibrated for the copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/design-one-byte-strings.md inventories every place that knows the flat UTF-16 string layout and designs a canonical one-byte (Latin-1) kind under header kind flag 1. docs/results/string-baseline-v1.md records tools/string-bench against Node 26.13.1 on macOS arm64 and Linux arm64 (15 paired rotated rounds) and the frozen v7 self-compile (5 paired rounds: native 70.6 s, 2.23 GB peak RSS; Node 26 76.7 s, 3.93 GB). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Strings whose code units are all at most 0xFF now take one byte per unit under header kind flag 1 (header 2^48+1); others keep two-byte UTF-16 storage (header 1). Kinds are canonical, so equal strings have equal headers and a one-byte string never contains a two-byte one (docs/design-one-byte-strings.md). Lengths, indices and comparisons stay in UTF-16 code units. - abi: one-byte header and flag constants; a second heap-debug string kind. - Collector: extents, Cheney sizes and scan checks by kind. - AArch64 and x86-64: kind-aware equality (header and length first), inline literal compares (one-byte literals read eight units a word), startsWith, charCodeAt (helper and inline paths), concatenation (widening one-byte parts), slices (a scan narrows two-byte slices), String.fromCharCode, Array.prototype.join, string-write, allocation sizes and literal pools. - IR: string-two-byte, and a kind operand on string-allocate, which join lowering computes from its parts. - Debugging: crash reports print one-byte strings; DWARF string variables are string pointers whose structure overlays units and bytes; LLDB/GDB formatters and heap snapshots decode both kinds. - Tests: collector extents and Cheney copies, kernel structure, IR storage, and an 82-check native fixture with a Node reference (tools/build-one-byte-strings-fixture.ts), passing on darwin-aarch64 and linux-x86_64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tools/native-one-byte-strings.test.ts (native) verifies the fixture twice under the gate's native runner, as the other string fixtures do, instead of a standalone build script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Slice 1 made indexOf, includes, lastIndexOf and split slower: they called string-starts-with at every position, now with kind tests. string-index-of (IR, AArch64 and x86-64) scans for the first search unit and compares the rest, per kind pair; a two-byte search never occurs in a one-byte source. split steps from match to match. On AArch64: - UXTL, XTN and SHRN #8 (llvm-mc-checked encodings) widen, narrow and scan two-byte slices eight units at a time; - copies move sixteen bytes per step, and copies of 2-16 bytes are two overlapping loads and stores without a loop; - String.fromCharCode converts each value once, keeping up to eight units packed in scratch words across the allocation; - string headers and lengths are read with separate loads. The one-byte fixture gains search position, NaN, overlong, empty and partial-match checks (92 checks). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
decimalInteger built a one-character string and a concatenation for every digit. It now builds each group of up to four digits with one String.fromCharCode, so String(n) below 10000 allocates once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
selectArrayAccesses proved s.charCodeAt(i) in bounds only when the length came from a load of the string's slot and the bound was that length's own slot. LICM leaves the length of a call result (stored to the string's slot in the same block) and preheaders copy it to another slot, so loops like for (i < text.length) text.charCodeAt(i) kept a checked, double-valued code unit. A value stored to a slot now counts as the slot's current value, and a store of one slot's current value to another copies its Len and Less facts. The string benchmark's codeUnits kernel drops from 41.6 to 14.2 ms (smoke): the hash loop becomes integer arithmetic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Slice 1 compared the header word too in every string === literal and string === string test, adding a load, a two-instruction constant and an eor/orr pair, which the compiler's discriminant chains repeat often. A 32-bit LDP at offset 4 now loads the header's high word (0, or 0x10000 for the one-byte kind flag) with the length, so a one-byte literal costs one sub more than before and a two-byte literal nothing. String.fromCharCode with one value keeps its unit whole in a scratch word, and units are stored with immediate offsets. Frozen v7 against main (5 interleaved rounds): cycles +0.05%, wall +0.2% (paired medians), peak RSS -2 MB, output identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/results/string-slice1-ab-v1..v3 record the string benchmark and the frozen v7 self-compile against main after slice 1 and each fix: v1 regressed (+2% frozen cycles), v3 is at parity on the self-compile (+0.05% cycles, +0.2% wall) and as fast as main or faster on all typed kernels but two at about +2%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
String(n) for a non-integer whose exact decimal has at most 15 significant digits now scales by 10^k until the product is an exact integer (checked with Dekker's two-product error term) and prints those digits: every decimal of at most 15 digits round-trips through binary64, so the exact expansion is the unique shortest one. Number(text) takes Clinger's fast path for at most 15 significant digits and exponents in [-22, 22], and trims only when an end may be whitespace. Integers below 10^8 format with one String.fromCharCode. Other values keep the exact big-integer paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
foundation/text/latin1.ts defines latin1Text, copyLatin1, asciiEndOfText and asciiEndOfBytes with portable bodies. Native builds bind them (project intrinsics, as sha256-rounds is bound) to new IR instructions: - string-from-latin1: one one-byte allocation and a byte copy; - string-copy-latin1: a byte copy, or narrowing eight units per step with an SHRN high-byte check, -1 at a unit above 0xFF; - string-ascii-prefix and bytes-ascii-prefix: sixteen bytes per step against the 0x80 (0xFF80 for halfwords) mask, the first flagged unit found with RBIT and CLZ (new AArch64 encodings). Indices must be exact uint32 values in range, else native code traps and the portable bodies throw. x86-64 scans a word at a time and copies with memmove. The three nonallocating instructions inline like typed-array accesses. tools/native-latin1-text.test.ts checks them natively against the portable bodies under Node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
encodeUTF8 and encodeUTF8Into copy ASCII runs with asciiEndOfText and copyLatin1, and scalarAt reads a surrogate pair with charCodeAt instead of codePointAt. decodeUTF8 returns wholly ASCII input as one latin1Text, and otherwise decodes ASCII runs in bulk into pieces that are joined once instead of appended per code point. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The paired A/B against main and slice 1 on macOS arm64: utf8 and clone1KiB now beat Node, numberString drops from 232 ms to 1.8 ms and utf8TwoByte from 140 ms to 21 ms, with no regressions. The design states the landing bar (every string-bench operation and PR #17's strings and stringBuild kernels at or below Node on both hosts) and documents the bound text primitives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Default Unicode casing of wholly ASCII text now maps letter by letter through asciiUppercase and asciiLowercase (foundation/text/latin1.ts), which native builds bind to a new string-ascii-case instruction: one allocation of the source's length and kind, then sixteen one-byte units per step on AArch64 (SUB, CMHI, AND and EOR on .16b lanes, with MOVI constants, new encodings checked against clang) and an overlapping last vector, or a unit loop for short and two-byte strings. x86-64 maps unit by unit. Locale-sensitive casing keeps its own path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
String.fromCharCode loaded each code unit raw and called the to-uint32 helper unless it was stored as a 32-bit word. It now uses wordValue, which reads integer-stored values and exact doubles inline and calls the helper only otherwise, and string-from-code-units counts as an integer-accepting use. create runs 5.7% faster (docs/results/string-s5-ab-v1.md). The one-byte fixture checks ToUint16 of fractional, non-finite, negative and large units at run time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The s5 A/B and its four-way attribution keep the inline code-unit conversion and reject integer digit groups, which slowed every small-integer formatting kernel by 5-17%. The design adds sliced strings: a view marker with the parent in the collector-traced owner slot, used for slices of at least 13 units of the parent's kind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Default casing maps ASCII text through foundation/text/latin1.ts since 90fa09a, so its module graph has seven modules, including that one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A template literal, or a typed string + chain of three or more operands, now allocates its result once (summed lengths, the kind from the pieces' two-byte flags, one string-write per piece, as join lowers) instead of copying the whole prefix at each step, and skips empty literal parts. A chain is fused only when every operand is a string, number or boolean that is neither speculative nor a BigInt, so others keep their existing path; converting each primitive operand right after evaluating it is unobservable. template runs 20% faster and beats Node; strings and stringBuild 5-7% faster (docs/results/string-s6-ab-v1.md). The one-byte fixture checks evaluation order, mixed operand types, numeric prefixes, empty and mixed-kind templates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
slice and substring results of at least 13 units in their source's kind are now 32-byte sliced strings (marker 1, kind flag 2 plus the one-byte flag): the address of their first unit inside the parent's data, and the flat parent, which the collectors trace and move the address with (cheney, parallel, mark-compact, nursery and fixups, like typed-array views). A slice of a slice points at the root parent. Strings stay canonical, so equal strings keep equal kinds. Readers resolve slices: each string helper flattens them on entry, inline charCodeAt dispatches on the header's high word, and equality, pooled literal compares and the join kind test look at the one-byte flag only. The diagnostics reporter, debugger formatter, heap snapshots and DWARF (string.slice) read them too. x86-64 still copies, so its readers never see a slice. slice and sliceTwoByte run 73-78% faster (docs/results/string-s7-ab-v1.md); readers' slice tests cost 5-7%, which follow-ups remove before landing. tools/native-sliced-strings checks every operation on slices, the 13-unit threshold, narrowing two-byte parents and collections that move parents only a slice keeps alive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rimitives Sliced strings now hold the byte offset of their first unit in the parent's units, then the parent, as V8's sliced strings do. The parent is an ordinary reference slot: Cheney's referenceSlot, the parallel collector's and the compactor's markReference reach it, and collectors copy slices verbatim, so the slice-specific relocation code goes. Every reader tests the sliced flag with one TBZ (new AArch64 TBZ/TBNZ encodings and a leaf-assembler testBit) on a header it loads anyway. Equality compares lengths first, sends equal header words to the helper and otherwise only pairs that include a slice; the helper reuses the prelude's loads. string-slice copies short results after one length test, skips the kind scan for one-byte sources and initializes slices inline. String helpers start on 64-byte boundaries and pad their loop heads to 32 bytes, so their copy and search loops never straddle a 64-byte fetch block wherever the code before them ends. For PR #15's cross-isolate transfer, @tint/abi/host gains nativeStringIsFlat and nativeFlatStringExtent, and two IR instructions bind through the memory intrinsics: string-flat (isFlatString) and string-flatten-into (flattenStringInto), which writes a string's flat image into a raw window, flattening slices. Like memory-write-bytes, the latter leaves the closed world for record-layout facts. Both backends lower them; tools/native-string-transfer.test.ts checks the images, including a one-byte image literal's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run 1 measures s8 against s6 (typed and general suites); run 2 measures s6, s8 and s8b, which adds the string helpers' aligned layout, together. Equality no longer pays for slices, and slice and sliceTwoByte fall to 0.22 and 0.20 of s6. Code placement moved several kernels by 3-9%; the aligned helper layout removes that for the string helpers' loops and is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
string-slice called the bounds helper, which clamps both bounds in double arithmetic, for every slice. Integer bounds (int64 storage, proven integral doubles, and doubles that convert exactly) are now clamped inline in integer arithmetic; NaN, infinities and fractions still call the helper, which receives the untouched doubles. With the inline view initialization, a slice of integer bounds calls no helper. The sliced strings fixture checks relative, clamped and empty bounds, and the non-integer bounds the helper keeps, as constants and run-time values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Slices lower the string kernels' peak RSS by 14%, and raise the frozen self-compile's by 0.39%, with 0.28% more instructions and cycles within the run's load noise. No retention fix is needed; the report assesses the collector-side one. The design lists sliced strings among the slices. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
onEmittedFunctions (code size reports, disassembly) listed only functions, so samples in the string, allocation and numeric helpers after each module's functions had no name. Each module's helpers now follow its functions as `helper:<kind>` ranges. In a Linux arm64 utf8TwoByte profile they held 30% of the samples. The observability test checks that helpers are listed and that no two ranges overlap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
utf8TwoByte ran 4.5x Node. A Linux arm64 profile put 38% of its time in decodeUTF8's byte state machine, 11% in encodeUTF8's scalar loop, and most of the rest in a helper call per ASCII run, an append and a String.fromCodePoint per scalar, and the join of the pieces. foundation/text/utf8.ts defines three primitives with portable bodies, bound in native builds like the Latin-1 ones (project intrinsics) to new IR instructions. A surrogate pair inside the range is one scalar, and a lone surrogate encodes as U+FFFD: - utf8ByteLength -> string-utf8-length: a range's UTF-8 byte count. On AArch64, one-byte text adds the units at 0x80 or above, sixteen per step (bit 7 of each, summed by a multiply). Two-byte text takes ASCII four units per step, then one scalar at a time. - writeUTF8 -> string-write-utf8: encodes scalar by scalar while the next one fits and returns the index after the last unit encoded. ASCII goes eight units per step, and two-byte text is narrowed by XTN. - utf8Text -> string-from-utf8: decodes the longest prefix of complete, valid sequences. A measuring pass yields the units, the canonical kind and the prefix length; then one allocation, then a decoding pass (ASCII eight bytes per step, widened by UXTL). The decoding pass stays within the measured units and bytes whatever the bytes hold, since a shared buffer may change between the passes, and it zeroes units it does not write. x86-64 runs the same contracts unit by unit, inline. The two nonallocating instructions inline like typed-array accesses. Indices must be exact uint32 values in range, else native code traps and the portable bodies throw. The codec is built on them. encodeUTF8 is one length pass, one allocation and one write, and encodeUTF8Into one write plus the length of what it wrote. decodeUTF8 takes the valid prefix in bulk (after a dropped byte order mark) and checks it reached the end: by its length for ASCII input, otherwise by re-measuring the decoded text, since valid UTF-8 is canonical. Only what follows an invalid or split sequence runs the byte state machine, which moved to its own function, so the fast path creates no closure. Tests: the portable bodies against TextEncoder and TextDecoder over every range of mixed samples, every capacity, every two-byte input and each lead's continuation bounds; decodeUTF8 against TextDecoder over chunks of every size with and without fatal mode and ignoreBOM; and tools/native-utf8-text.test.ts, which checks the bound instructions natively against references written in the fixture (both string kinds, slices, word and vector boundaries, invalid and truncated input). The Script runtime captures one more source text (30). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The orchestrator's condition 2 asked for a measured minimum instead of V8's 13. Typed images of the kernels that slice, differing only in the minimum (9, 13, 16, 24, 32), ran 15 paired rotated rounds (docs/results/string-slice-minimum-v1.md). `slice` gets faster with each step down (0.916x from 13 to 9) and slower with each step up (1.05x, 1.085x, 1.129x). `sliceTwoByte` is flat from 9 to 16 and slower above, and the other kernels do not move. Nine is the smallest allowed value: inline literal compares read up to eight data bytes of flat strings, so a slice needs more. At 9-12 units, a one-byte slice is the size of the copy it replaces, and a two-byte slice is smaller. The sliced-strings fixture now covers lengths from 5 and compares the shortest slice with pooled literals and the longest inline one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The s11 A/B (docs/results/string-builder-ab-v1.md) measured build-loop-strings: `stringBuild` ran 21.5% faster than without it, but `clone1KiB` (+5.0%), `utf8TwoByte` (+2.9%) and `json` (+2.7%) slowed down. Build remarks showed that of their loops only foundation's finishString was rewritten, a loop over a few large parts. Plain `+=` keeps the first part without copying and copies exactly after that. The builder copied every part into a buffer twice the needed size and returned a slice of it. The first three growths now concatenate exactly, as the loop did, with a growth count in a fresh slot. Until then the buffer is exactly full, so it is the prefix. A loop of a few appends copies no more than before and its result stays flat. Longer loops switch to the doubling buffer at the fourth growth. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`text += (words[i] ?? "") + separator` read `text` before evaluating the piece, as JavaScript orders it. The piece's `??` branches, so the read and the concatenation landed in different blocks, and build-loop-strings (which needs them in one) skipped the loop. The `concat` and `concatTwoByte` kernels are such loops. `s += piece` and `s = s + a + b` now read `s` after the pieces when that is unobservable: `s` is a local without a cell, so nothing else can write it, and the pieces hold no assignment, update, function or class syntax. Calls cannot assign an uncaptured local. Anything else keeps the source order. Both concat kernels' loops, and 15 more runtime loops in the string bench image, are now rewritten. The string-builder fixture adds branching pieces and appends whose pieces assign the string, directly and through a closure, under Node and natively. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The s12 A/B (macOS arm64, 15 paired rounds) put utf8TwoByte at 1.23x Node, down from 4.65x, but ASCII `utf8` rose from 0.63x to 1.09x: ASCII text and input had moved from one Latin-1 scan and copy, sixteen bytes per step, to the UTF-8 loops at eight. A Linux profile of utf8TwoByte put 31% in string-utf8-length, half of it re-measuring the decoded text to confirm the whole input was valid. - ASCII text and input take the Latin-1 scan and copy again. - string-from-utf8 gains `whole`, bound as utf8WholeText: the decoded text when the whole range is valid, else the empty string, which a nonempty valid range never decodes to. The measuring pass already leaves the bytes after the prefix in x15 (RDX on x86-64), so the check is one branch. decodeUTF8 asks for the whole input first and only re-measures a prefix when the input is not all valid. - The two-byte length pass takes ASCII eight units per step, and the two-byte decoding pass sixteen bytes, widened by two UXTLs. Tests cover utf8WholeText against TextDecoder over every range and in the native fixture, and the IR round trip with `whole`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
String.fromCharCode(c), single-digit String(n) and the like allocated a 24-byte string per call; `stringBuild` appends 24 of them per round. V8 keeps a table of single-character strings. On AArch64, a module that converts one code unit now heads its literal pool with the 256 one-unit strings of units 0-255, in order and 32 bytes apart (their pooled size), so "\u0000"'s address is the table's base. string-from-code-units with one unit below 256 returns base + unit * 32 without allocating, and other units allocate as before. Literals of one such unit share the table. The one-byte strings fixture checks units 0-0x1FF against literals, joins, slices and map keys, under Node and natively. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests' TypeScript lib predates ES2024, so String.prototype.toWellFormed failed the workspace type check (macOS CI). The decoder with ignoreBOM gives the same expected text: an encoded lone surrogate is U+FFFD, and a leading U+FEFF is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/results/string-s12-ab-v1.md: s6 vs s11 vs s12 (354623d), 15 paired rounds on macOS arm64. Against Node: `concat` 0.95x (from 1.50x), `concatTwoByte` 1.07x (from 2.28x), `utf8TwoByte` 1.23x (from 4.65x) and `slice` 1.76x, with `clone1KiB` and `json` back from their s11 losses. ASCII `utf8` rose from 0.63x to 1.09x, which 8d81471 addresses. Frozen v7 against s6: cycles median -0.38%, instructions +0.29%, peak RSS +0.38% (the same as at a minimum slice length of 13). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The native subset rejects a conditionally spread optional field in a
union-typed instruction literal ("each object variant requires one
compatible context variant"), so the codec returns each form from its own
branch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A loop reading code units of a string it never changes (codeUnits' `text.charCodeAt(i)`, hashString, scanners) redid the string's kind dispatch at every read: a header load, a compare per kind and, for a slice, its parent and start. In codeUnits that was 7 of the loop's 27 instructions. The version-string-loops pass (last, after bound-counted-loops) takes each small loop (at most 96 instructions) whose code-unit reads load a string slot the loop never writes. Its preheader tests the string once: a flat one-byte string enters a copy of the loop whose reads of that slot are marked `unitKind: "one-byte"`, a flat two-byte string a copy marked `"two-byte"`, and a slice the loop itself, unchanged. The copies share the loop's slots and exits. As in bound-counted-loops (whose recordReadsKept it now shares), a loop whose copies would join a proven record read's path at an exit is left alone, as are functions with debug metadata. A marked in-bounds read is its load alone on AArch64 (ADD and LDRB or LDRH); x86-64 drops the kind test. string-code-unit's `unitKind` rides the IR codec (flags 8 and 16) and round-trips in the store test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`%` converted both operands to doubles, checked each for an exact int32 by a round trip (FCVTZS, SCVTF, FCMP), divided with 32-bit SDIV and converted the remainder back. equality spends 15% of its samples in `(i + round) % source.length`, and create 17% in `% 26`, `% 20` and `% 10`. When both operands are proven exact integers (int64 storage, 32-bit words or bounded safe integers), AArch64 now reads them as int64s and uses 64-bit SDIV and MSUB, exact below 2^53. A nonzero constant divisor is materialized directly and needs no zero test; a zero divisor still gives NaN. A zero remainder takes the dividend's sign: from its sign bit for an int64 dividend (never -0), else from `left * +0`. The remainder is an int64 result when its uses take one, the divisor is a nonzero constant and the dividend is proven non-negative (constants, lengths, code units, uint32 and >>> words, & with a constant mask below 2^31, and +, * and % of such values), so no -0 can arise wherever the value flows. The divisor is accepted as an integer use. The dividend is not: its zero sign shows in the remainder. The zero-sign analysis marks a dividend's sign as observed when the remainder's is. Tests: tools/native-remainder.test.ts gains integer remainders used as indices with constant divisors, observed -0 remainders, negative and zero constant divisors and dividends near 2^52. The emitter tests use a fractional dividend to reach the helper and check that exact integers need none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`String(i)` formatted and allocated every time: in `create` (64 `String(i)` per round over i < 64) numberToString's integer path took about 35% of the samples. V8 answers repeated conversions from its NumberStringCache. numberToString now asks numberStringCached first and caches what it formats with cacheNumberString (foundation/numeric/number-string-cache.ts, bound like the Latin-1 primitives to the new number-string-cached and number-string-cache instructions; the portable bodies hold nothing). The table (nativeNumberStringCacheWord, nativeNumberStringCacheEntries in @tint/abi/host) has 256 direct-mapped entries, each a number's bits and then its string, indexed by the top bits of the bits times 2^64 / golden ratio. It is a one-byte string object reached only through word 15 of the published allocation state (context +56), which holds its managed offset. The first store after a collection allocates and zeroes it. Every collection, generational (minor and major) and copying, clears that word before tracing. So the table is never traced, and it and any string only it references die there: no entry outlives a move, no barrier is needed, and nothing is retained across collections. The copying runtime's published state grows to sixteen words for word 15; the region runtime publishes none, so its lookups miss. On AArch64 a lookup is a few loads and a multiply; x86-64 misses and drops stores, like the portable bodies. tools/native-number-string-cache.test.ts converts integers, negatives, fractions, extremes, -0, NaN and the infinities twice per round, around collections forced by churn in an 8 MiB heap, under the generational and copying runtimes, against Node's strings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Linux arm64 profile of the general `json` kernel (stringify and parse of 32 small records) put about 30% of its samples in string work: the parser's string() collecting parts unit by unit, one-unit charAt strings compared against punctuation, literal checks that sliced the source, and quoteJSONString escaping unit by unit through a string builder. - string() scans to the closing quote and returns one slice of the source when it meets no escape or control character. Otherwise the escape loop continues from there, as before. - Punctuation, signs and exponents compare code units (charCodeAt) instead of one-unit strings, and null/true/false are checked with startsWith, not with a slice per literal. - quoteJSONString scans first: a string with nothing to escape (and no surrogate to check) is quoted whole in one allocation. Otherwise the escape loop starts at the first such unit. The native `json` kernel keeps Node's checksum. Its Linux run fell from about 155 to 131 ms per iteration (indicative; the timed A/B follows). New tests compare parsing with JSON.parse wherever escapes fall, reject truncated literals and strings, and quote strings with a special unit before, after and between plain runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The design's plan lists the kind-dispatch hoist (version-string-loops), the number-string cache behind numberToString with its collection policy, and the JSON string paths among the done fast paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stringToNumber scans the common case, an optionally negative decimal of at most 15 significant digits and 22 fraction digits, in one loop that accumulates the mantissa and finishes with Clinger's fast path; every other form falls through to the general path unchanged. numberToString formats positive integers below 10^8 directly, digit extraction multiplies by 0.1 and 0.0001 (floor-exact over the ranges used, checked exhaustively) instead of dividing, and short exact fractions from 1 up join their integer digits, the point and zero-padded fraction digits in one concatenation rather than slicing a digit string. Linux arm64 numberString, interleaved runs of saved images: 2.45 ms at 1c6c3ed to about 1.5 ms (Node 26.13.1: 0.79 ms on the same host). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ToInt32, ToUint32 and ToUint16 of a double take their first step, truncation toward zero, exactly as fcvtzs does, and fcvtzs maps NaN to zero, so its low bits are the conversion's for every operand below 2^63 in magnitude, fractional or not. The inline path therefore needs no scvtf/fcmp round trip: one cmn x9, x9 sends magnitudes from 2^62 (saturation, infinities, exactly 2^63) to the ToUint32 helper. Bitwise operators and String.fromCharCode units lose three instructions each. tools/verify-hosted-bitwise-integral.ts gains boundary operands around 2^62 and 2^63, large fractions and a ToUint16 result per operand, and tools/native-bitwise-integral.test.ts runs it in the native gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ollide The cache took an entry from the top bits of a multiplicative hash of a number's bits, so a loop's handful of small integers collided like random keys: in the create kernel about one in five of its 64 values shared an entry with another and evicted it every round, missing each time. An entry is now the low bits of the value's truncation plus its bits' low word and that word's upper 24 bits. Integers below 2^21 have a zero low word, so consecutive ones take consecutive entries, as V8 indexes small integers by their low bits; other numbers still mix their fraction bits. The lookup is the same length. Linux arm64 create, interleaved runs of saved images: 12.9 ms to 11.9 ms (Node 26.13.1: 9.1 ms); numberString, whose values are all distinct, is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The integer `%` path needs a non-negative dividend, but codegen proved non-negativity only block-locally, never for a load, so a loop counter's remainder by a constant went through doubles. Integer slots (never -0) whose every store is a proven non-negative value are now non-negative slots, their loads non-negative values; the forward pass repeats until no slot loses its fact. And an exact integer modulo a nonzero integer constant d is a bounded word (below |d|), so sums such as `98 + i % 20` stay int64s too, and String.fromCharCode reads them without converting. Linux arm64 create, interleaved runs of saved images: 12.2 ms to 11.0 ms (Node 26.13.1: 9.1 ms). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A one-byte concatenation of at most eight units has two flat parts (slices are longer), each with eight readable data bytes, so its data is one word: the left part's word masked to its length, or'ed with the right part's shifted above it (the left word whole when it fills all eight). Bytes past a string's length are never read, so stale tails need no clearing. Such results now store header, length and that word inline instead of calling string-concat-copy, whose per-part slice and copy dispatch dominated short joins like "v" + String(i). tools/native-short-concat.test.ts joins parts of every length from 0 to 9, with stale tails and two-byte parts, against Node. Linux arm64 create, interleaved runs of saved images: 13.1 ms to 12.5 ms (under heavier host load than the previous commit's runs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Joins of three or more parts and the loop string builder write each part with string-write, which always called string-write-copy. A flat one-byte part of at most eight units into a one-byte target is now one data word, loaded and stored inline, whenever the store stays inside the target's data (its length rounded up to eight bytes). Every builder writes its parts in offset order, so bytes stored past a part belong to a later part or to spare capacity nobody reads; slices, two-byte parts, longer parts, the last part when its word would leave the target, and overruns (which trap) still take the helper. Offsets already held as integers are no longer converted from doubles. tools/native-short-concat.test.ts adds three- and four-part joins, templates and loop appends at every part length around word boundaries. Linux arm64, paired 15-round string-bench against 2bb05ba (Node 26.13.1): stringBuild 1.31x to 1.16x Node, strings 1.09x to 1.06x, concat 0.75x to 0.67x, splitJoin 0.85x to 0.80x; others unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`x | 0` and `x ^ 0` are ToInt32(x): the other operand's low 32 bits. They materialized the zero, or'ed it in and then sign-extended, two instructions on the loop-carried chain of every `(hash * 31 + unit) | 0` style accumulator. A zero operand now folds away (like constant shift counts), and the result is one sxtw from the operand's word, or a 32-bit move for word storage. tools/verify-hosted-bitwise-integral.ts adds x ^ 0, 0 | x and x | -0 over its boundary operands. Linux arm64, paired 15-round string-bench against c617fd5: codeUnits 1.33x to 1.16x Node, codeUnitsTwoByte 1.36x to 1.18x, stringBuild 1.21x to 1.14x; others unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`(Math.imul(h, 31) + u) | 0`, every hash and checksum accumulator, ran imul, a sign extension, a 64-bit add and another sign extension on its loop-carried chain. When an imul's only use is a `+` of an exact integer and every use of that sum reads only its low 32 bits (bitwise operators and imul), the low bits of the sum depend only on the low bits of its addends: the product now skips its sign extension and the sum is a 32-bit add, leaving madd, add and the final sxtw on the chain. Facts are use-based and block-local; the addend's exactness is checked at the product, which marks its sum. tools/native-truncated-sums.test.ts hashes code units through |, >>>, ^ and &, with wide and negative addends and a sum that also has a full-width use, against Node. Linux arm64, paired 15-round string-bench against e9a0dfb: codeUnits 1.18x to 1.00x Node, codeUnitsTwoByte 1.17x to 0.98x; others unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The truncated-sums fixture gains `(Math.imul(p, k) + d) | 0`, `^` and `>>>` over double addends: fractions, NaN from an out-of-range charCodeAt, infinities and integers around 2^52, 2^53 and 2^63, each folded into a checksum that never resets. (A 32-bit fast path for integral double addends was measured and dropped: it changed no kernel.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASCII UTF-8 back on the Latin-1 primitives and one-unit strings from the pooled table (7582487) against s6 and s12 on macOS arm64: utf8 0.58x Node (0.561x of s12), utf8TwoByte 1.10x (0.888x), strings and stringBuild gain 4-5%; everything else within 2.5% of s12. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The three- and four-part joins and loop appends now include two-byte parts of one to nine units, so two-byte targets are written at every offset. (Inline one- and two-word writes for two-byte parts were measured and dropped: concatTwoByte gained 1-2% while template lost 5% to the larger write sites.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Typed String(n), templates, `+` and joins called numberToString, which called numberStringCached: two calls even on a cache hit. They now emit the number-string-cached lookup inline (no number converts to "", its miss) and call the formatter only on a miss. That formatter is the new numberToStringMissed, which formats and caches without looking up again; numberToString (the runtime's entry, as JSON.stringify uses) keeps its lookup and calls it. Sources without numberToStringMissed (frozen snapshots) keep numberToString as the typed formatter. Linux arm64, paired 15-round string-bench against 3863ed8: create 1.21x to 0.93x Node, strings 1.06x to 0.95x, stringBuild 1.17x to 0.98x, template 0.52x to 0.39x; numberString, whose values all miss, unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Stream brief: one-byte (Latin-1) strings, like V8's, with exact JS semantics. UTF-16 code-unit indexing, lengths, comparisons and surrogates behave the same whatever the representation.
Landing bar
This PR lands as one change, and only when every operation in
tools/string-bench(typed and general suites) is at or faster than Node 26.13.1 on both macOS arm64 and Linux arm64. The set includes PR #17'sstringsandstringBuildkernels, which moved to this stream. PR #15's isolated 1 MiB structured-clone case also depends on it. It stays in draft until then.Where it stands (Linux arm64, paired 15-round string-bench vs Node 26.13.1, at
eee4d9b42)upperCase/jsonmacOS arm64 A/Bs for s14–s19 are queued behind the shared timing lock; the last completed one is s13.
slice,sliceTwoByteandequalityare limited by number representation that is shared codegen: double loop counters bounded bynumberparameters, 32-bit-only integer slots,%with a variable divisor andcharCodeAtresults that may be NaN. V8 speculates int32 for all of these. See the coordination notes below.Status
tools/string-bench, the design and the baseline.string-index-of, inlinecharCodeAtkind dispatch, pair-load equality, NEON widening and narrowing, loop-free small copies, a bounds proof through stored lengths, and one-unit strings below 256 from a pooled table.string-utf8-length,string-write-utf8,string-from-utf8withwhole) on both backends.efec21899: code-unit loops entered through a copy per flat string kind (version-string-loops).400d058e0: exact integer remainders as int64sdiv/msub(shared codegen).1c48d378d: a runtime-owned number-string cache, dropped at every collection;407fc2cfb: JSON strings parsed as one slice and quoted whole.fde35a819: one-pass decimal parsing and division-free digit formatting.6cb3577d0: ToInt32 without an integrality round trip;07dff2efc: cache indexed by truncation;1f84400e7: non-negative counter remainders stay integers.2bb05ba9f: short one-byte concatenations in one data word;c617fd5a6: short one-bytestring-writeparts as one word.e9a0dfbc1:x | 0as onesxtw;3863ed868: truncated sums of products in 32 bits.eee4d9b42: typed code looks number strings up inline and formats only misses (numberToStringMissed).string-write;Math.imulinhashString;bound-counted-loops.Validation so far
3863ed868).native-number-text,native-number-string-cache;native-bitwise-integral(new in the gate),native-truncated-sums,native-remainder;native-short-concat,native-one-byte-strings,native-sliced-strings,native-string-builder,native-utf8-text,native-latin1-text,native-string-transfer.built-ins/String2443/2443.Coordination
tools/typed-bench.perf/loop-constantsowns the loop-invariant constants; this branch merges main once it lands.mapKeysis mostlyfindMap/setMapHashed), and the general runtime behindupperCaseandjson.%with variable divisors,charCodeAt) as a shared-codegen item forsliceandequality, and a V8-style split cache forequality.🤖 Generated with Claude Code