Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: a47f352 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Published pnpm add viem@pr-5537
pnpm add [email protected] |
|
Bundled into #5543 as its own commit, so this PR is superseded. Closing in favour of the bundle. |
From the sync encoding primitives section of a performance and memory audit. Every change keeps outputs and errors identical; see Behavior.
Summary
padBytescopies withUint8Array.setinstead of a per-index loop. Sizes that aren't safe integers (NaN, fractions) keep the loop, because it skips the fractional indices they produce. Empty views skipset, which throws on detached buffers.concatHexbuilds the result in a plain loop instead ofreduce.trimcompares char codes and bytes directly instead of calling.toString()on every element, with separate loops for hex and bytes.padHex,sliceHex,concatHex,trimstrip a leading0xwithslice(2), falling back toreplace('0x', '')when the value doesn't start with it, so values without a prefix behave as before.sizechecks for the0xprefix withtypeofandstartsWith, which is whatisHex(value, { strict: false })did.Behavior
Unchanged. A harness compared
mainand this branch on 103,377 calls on Node 26, Node 24 and Bun 1.4: identical return values and identical thrown errors (class and message). Inputs includedpadHex,padBytesandpadwith sizesnull,0,-1,1.5,NaNand an unknowndir,concatHexwith values without a prefix or with0xin the middle,trimin both directions, all-zero and odd-length values,sliceHexandslicewith negative, reversed and fractional offsets in strict mode,sizeon non-strings, and detached views.New tests (snapshots recorded on
main) coverpadByteswith a detached view and withNaNand fractional sizes (the per-index fallback), plus values without a0xprefix inpadHex,concatHex,sliceHexandsize, andtrimedge cases.Benchmarks
SKIP_GLOBAL_SETUP=true vitest bench --project core --run <file>, Node 26.13, same bench file onmainand this branch. The orb is shared, so expect ±10–20% noise.padHex4 B → 32padBytes4 B → 32padBytes20 B → 32, righttrim32 B hextrim32 B bytesconcatHex10 × 32 BconcatHex1000 × 32 BsliceHex1 KB, 4 to 36size32 B hexIn a standalone loop,
trimon 32 bytes goes 1.59M → 10.0M ops/s. A smaller patch that only replaced.toString() === '0'and kept the shared loop reached 1.7M, which is why bytes and hex now have separate loops.New bench files:
concat.bench.ts,slice.bench.ts,size.bench.ts.pad.bench.tsandtrim.bench.tsgained cases.Size
import * from 'viem' (esm)const viem = require('viem') (cjs)import * from 'viem/account-abstraction'import { privateKeyToAccount } from 'viem/accounts'import * from 'viem/actions'This PR fits the current limits on its own (
pnpm sizewith time measurement off, since there's no Chrome here). All five PRs in this series together go over three limits by 41–122 B and leaveviem/actions6 B under its limit. So every PR in the series raises those four limits by 0.5 kB in a separatechore:commit (precedent: 9677703). The edit is identical in each PR, so git merges them cleanly in any order, and no intermediate merge state breakspnpm size.Series: #5534 (
bytesToHex,stringToHex,stringToBytes), #5535 (hexToBytes,toBytes), #5536 (number conversions), #5537 (data utils), #5538 (TextDecoder,normalizeSignature,formatUnits). They touch some of the same files in separate hunks; any merge order applies cleanly (checked both orders).Checks
pnpm test --project core --run src/utils/data: passing.src/utils,src/accounts,src/siwe: the only failures are the Anvil-dependent tests that fail identically onmainhere (no Anvil in this environment).main: full, apart from two branches that were already uncovered (slice.tsL67,Value.tsL29).tscclean forsrcand the changed test and bench files.pnpm knip --productionclean on the five PRs merged together.