Skip to content

perf: reduce IP parsing allocations and BigInt operations - #41

Merged
yourtion merged 1 commit into
mainfrom
perf/ip-parsing
Oct 25, 2026
Merged

yourtion merged 1 commit into
mainfrom
perf/ip-parsing

Conversation

@yourtion

Copy link
Copy Markdown
Owner

Every lookup currently allocates intermediate arrays and reconstructs an already-canonical IPv4 string; IPv6 values also require sixteen per-byte BigInt steps. CPU sampling identified these as recurring query costs. Scan IPv4 decimal characters directly into one byte array, retain the validated input string, and assemble complete address integers in unsigned 32-bit groups. Public APIs, strict literal acceptance, canonical addresses and all 128 address bits are preserved.

Add shared regressions covering all 256 byte values in each IPv4 octet, rejected leading-zero variants, malformed decimal syntax, and every set/cleared bit across IPv4/IPv6 word boundaries.

Standard-record query throughput against built main 9bd36dbeedeffd50c92613a0184d4a4feb266f66, median queries/s:

Runtime Family Main Optimized Change
Node 24.19.0 IPv4 259,123 479,727 +85.1%
Node 24.19.0 IPv6 150,312 174,450 +16.1%
Bun 1.4.4 IPv4 379,940 699,925 +84.2%
Bun 1.4.4 IPv6 190,258 237,225 +24.7%
Deno 2.9.6 IPv4 190,732 333,727 +75.0%
Deno 2.9.6 IPv6 132,689 150,633 +13.5%

The same pinned XDB files and 4,096-address corpus were measured in five fresh sequential processes per case, with 20,000 warm-up and 500,000 throughput queries per process. All 120 workers checked every result and the timed checksum. Raw-record throughput, latency, loading, memory and source/compiled hashes are retained in docs/benchmarks/2026-10-24-ip-parsing.json; these observations are specific to this host and workload, and some IPv6 run ranges overlap. Only this repository's revisions are measured; benchmarks remain outside CI.

Validation: 73 core/reference/release tests passed. Real tarball consumers passed on Node 22.12.0/24.19.0 (59 each), Bun 1.2.0/1.4.4 (57 each) and Deno 2.0.0/2.9.6 (57 each), including public custom examples, declarations, permissions and data hashes. oxlint, oxfmt and TypeScript passed under both supported Node versions.

@yourtion
yourtion merged commit 4e5c346 into main Oct 25, 2026
12 checks passed
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.

1 participant