Skip to content

fs: improve cpSync no-filter copyDir performance#58461

Merged
nodejs-github-bot merged 1 commit intonodejs:mainfrom
dario-piotrowicz:dario/move-cpsync-copyDir-to-cpp
Jun 7, 2025
Merged

fs: improve cpSync no-filter copyDir performance#58461
nodejs-github-bot merged 1 commit intonodejs:mainfrom
dario-piotrowicz:dario/move-cpsync-copyDir-to-cpp

Conversation

@dario-piotrowicz
Copy link
Member

move the logic in cpSync that copies a directory from src to dest from JavaScript to C++ increasing its performance

Note: this improvement is not applied if the filter option is
provided, such optimization will be looked into separately


Example of perf improvement
// index.js
const fs = require('node:fs');
const path = require('node:path');

const fileName = path.basename(__filename);

fs.rmSync('./tmp', { recursive: true, force: true });
fs.rmSync('./tmp-out', { recursive: true, force: true });

fs.mkdirSync('./tmp', { recursive: true });

for (let i = 0; i < 100; i++) {
    fs.writeFileSync(`./tmp/file-${i}.txt`, `This is file number ${i}`);
}

for (let i = 0 ; i < 10 ; i++) {
    fs.mkdirSync(`./tmp/dir-${i}`);
    for (let j = 0; j < 100; j++) {
        fs.writeFileSync(`./tmp/dir-${i}/file-${j}.txt`, `This is file number ${j} inside dir number ${i}`);
    }
}

fs.cpSync(`./tmp`, `./tmp-out`, { recursive: true });

const runs = 500_000;
for (let i = 0 ; i < runs; i++) {
    fs.cpSync(`./${fileName}`, `./tmp/${fileName}`, { errorOnExist: true });
}

Screenshot at 2025-05-26 00-29-31

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants