Skip to content

perf(0.x): hot-path speed and memory improvements, and Blobs.to multi-blob fix - #687

Merged
jxom merged 7 commits into
0.xfrom
perf/0.x-hot-paths
Nov 16, 2026
Merged

jxom merged 7 commits into
0.xfrom
perf/0.x-hot-paths

Conversation

@jxom

@jxom jxom commented Nov 15, 2026

Copy link
Copy Markdown
Member

Performance and memory pass on the v0 line, plus the wins ported from the matching main pass. Every change was measured before/after with pnpm bench (same bench files on both sides) and a heap harness (bytes allocated and retained per call). Results are byte-identical to before, except the Blobs.to fix below.

Fix

Speed and memory

Area Speed (ops/s) Memory per call
Blobs.to, 6 blobs 7 → 771 (116x) 23.0 MB → 763 KB allocated
Blobs.to, 100 KB of 0x80 33 → 5,578 (168x) 19.9 MB → 101 KB
Blobs.from, 6 blobs 560 → 1,052 (1.9x) 6.9 MB → 788 KB
Hex.fromBytes (native toHex when available) 32 B 1.6x, 1 KiB 3.75x, 64 KiB 4x 1 KiB: 35 KB → 4.2 KB allocated; up to 32.6 KB → 2.1 KB retained
Bytes.fromHex (nibble table, no copies) 1.2x small, 1.6–1.7x at 1 KiB+ —
Hex.concat / slice / padLeft / trimLeft 1.85x / 1.25x / 1.2x / 1.8x —
Bytes.padLeft / trimLeft / toBoolean 1.9x / 2.1x / 1.8x —
Bytes.toBigInt, small value 2.5x —
Hex.fromNumber, number 1.7–2x —
Hex / Bytes / Address .validate, invalid input 47x / 50x / 25–35x ~2.3–3.4 KB → 0–56 B
ABI decode: Seaport / dynamic / uint256[1000] / address[100] 1.7x / 1.4x / 1.67x / 1.37x uint256[1000] 644 → 312 KB allocated
TxEnvelopeEip1559 serialize / deserialize / getSignPayload 1.21x / 1.24x / 1.12x ~40% less allocated
Base58.fromBytes / toBytes, 256 B 5.6x / 2.4x 73 → 20 KB / 110 → 15 KB
TypedData.getSignPayload / hashStruct 1.36x / 1.40x 53.8 → 44.6 KB
VirtualMasterPool.resolve(), 8 concurrent cold calls 3.8–9.6 ms → 1.3–1.5 ms 8 pools → 1

ABI encode is neutral to slightly faster (1.0–1.17x). Bench noise between runs is about ±10%.

Notes

  • Zero-copy views are used only internally, where the view is consumed immediately (decodeAddress). Public Bytes.slice/trim and Rlp keep copy semantics so callers' buffers can't be aliased.
  • No constant-time behaviour changed.
  • The TypedData type-hash cache is bounded (1,024 entries) and cleared by Caches.clear.
  • The Hex.fromBytes fallback path (no native toHex, e.g. Node 24 in CI) was tested by deleting toHex and rerunning the core suite.
  • Rejected, with measurements: native Uint8Array.fromHex (slower for small inputs), parallel imports in resolveNode (no measurable gain), pbkdf2Async in Keystore.toKeyAsync (noble yields only to microtasks, so timers still block).

Tests

Offline core + tempo-unit suites match 0.x (3,216/3,257; the 33 failures need Anvil with a mainnet fork, which this environment can't reach). New: two Blobs.to regression tests (both fail on the old code) and an unaligned repeated-read cursor test. Differential checks against origin/0.x cover Hex/Bytes/Address helpers, Bytes.fromHex errors, Base58, Bytes.toBigInt, cursor read accounting (3,000 sequences), and Blobs.

ampagent and others added 5 commits November 15, 2026 22:59
- Hex.fromBytes uses native Uint8Array.prototype.toHex when available.
- Bytes.fromHex decodes through a nibble table without copying the input.
- Hex concat/slice/pad/trim strip the prefix without a search; Bytes
  pad/trim avoid per-byte loops and string conversions.
- Hex.fromNumber fast path for unsigned safe integers.
- Bytes.toBigInt builds small unsigned values as numbers.
- Hex/Bytes/Address validate return false without throwing.
- ABI decode: cursor tracks repeated reads in a bit set, decodeNumber
  shortcuts uint256, decodeAddress encodes a subarray, and
  getArrayComponents skips its regex for non-array types.
- Checksum cache hits do one lookup.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e11f-5ff6-753c-a73f-89ceda0ed7a9
Co-authored-by: jxom <jake@tempo.xyz>
Blobs.to treated the last 0x80 byte of any blob as the terminator, so
multi-blob payloads with a 0x80 byte in a non-final blob lost data. It
now finds the terminator once in the final blob and copies with byte
loops, which also removes the quadratic rescan. Blobs.from writes field
elements directly instead of through a cursor.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e11f-5ff6-753c-a73f-89ceda0ed7a9
Co-authored-by: jxom <jake@tempo.xyz>
@vercel

vercel Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ox Ready Ready Preview Nov 16, 2026 1:19am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T01:14:57.918152Z b2f312d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Published ox@0.0.0-pr-687-b2f312d under the pr-687 dist-tag, which follows this pull request until it closes.

pnpm add ox@pr-687
pnpm add ox@0.0.0-pr-687-b2f312d

@jxom
jxom merged commit d693734 into 0.x Nov 16, 2026
14 checks passed
@jxom
jxom deleted the perf/0.x-hot-paths branch November 16, 2026 01:22
@github-actions github-actions Bot mentioned this pull request Nov 16, 2026

This branch was successfully deployed

1 active deployment
Preview — b2f312de Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants