Repository navigation
perf: reduce IP parsing allocations and BigInt operations - #41
Merged
Merged
Conversation
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.
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: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.