fs: add c++ fast path for writeFileSync string utf8#49884
fs: add c++ fast path for writeFileSync string utf8#49884nodejs-github-bot merged 1 commit intonodejs:mainfrom
Conversation
|
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. |
98c5cd5 to
7ab6586
Compare
|
Rebased on latest main and addressed various review comments. Should be good for review fully now. |
|
@santigimeno and/or @bnoordhuis, would you mind checking/reviewing the latest revision? Uses a write loop like original JS source now. Thanks! |
67f5efd to
6704ac9
Compare
6704ac9 to
6747d5d
Compare
|
Rebased on latest main (+ poking flaky GH CI) |
|
Landed in 4466dee |
|
@CanadaHonk Do you have benchmark results from our CI? I don't we should mention local benchmarks in the changelog. |
|
@RafaelGSS Not any recent/existing :p |
|
Some of our tests using Is this related? |
|
Was |
|
base64 writes are also a thing, as it covers binary writes when content is already in base64 Left column is downloads/month
|
Summary
Added fast path in almost entirely C++ for
writeFileSyncwith UTF8 encoding and string data. Also improvesappendFileSyncas it just useswriteFileSyncunder the hood. Only string data as Buffer seems questionable in benchmarks for this so I'll just leave it for strings for now.TL;DR: This makes
writeFileSync(path, data: string)UTF8 up to ~2.5x faster depending on data size, especially when using file descriptorsBench results
Benchmark in this PR
Note: running locally on Linux/i9/SSD
Benchmark CI (old): https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1421/
Alternative benchmark
Alternative benchmark using Bun's bench for
fs.copyFileSync(string data, using paths)Current (main)
This PR
Long ascii:
6.14µs->3.46µs(~1.8x speedup)Long utf8:
40.02µs->18.25µs(~2.2x speedup)