Skip to content

perf(ltx): compute the CRC-64 and the LZ4 blocks without BigInt - #53

Merged
mcollina merged 2 commits into
mainfrom
perf/ltx-encode
Nov 23, 2026
Merged

mcollina merged 2 commits into
mainfrom
perf/ltx-encode

Conversation

@marcopiraccini

@marcopiraccini marcopiraccini commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

The checksum and the compression of each page did 64-bit arithmetic with BigInt, one byte at a time. In a CPU profile of a thread replicating many databases which write 100 KB to 1 MB each, Crc64.update and compressBlock took 70 to 90% of the time, and the thread stayed at 100% of its event loop.

Both now handle 64-bit values as 32-bit halves. The output is byte for byte the same: new tests compare it with the previous code, kept as a test helper, on random and database-like pages, and the Go fixtures still match.

BASELINE=1 pnpm bench:encode, the benchmark added in bench/bench-ltx-encode.ts: 2,048 pages of 4,096 bytes, best of 5 rounds, Node.js 26.13.1.

Operation Pages Now BigInt Speedup
CRC-64 text 469.6 MB/s 20.2 MB/s 23.3x
LZ4 text 341.1 MB/s 23.9 MB/s 14.3x
both text 197.6 MB/s 10.9 MB/s 18.1x
CRC-64 random 473.6 MB/s 20.5 MB/s 23.1x
LZ4 random 276.7 MB/s 34.1 MB/s 8.1x
both random 174.6 MB/s 12.8 MB/s 13.7x

Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a benchmark?

Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
mcollina merged commit 005097b into main Nov 23, 2026
19 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.

2 participants