Time to find a non glob path increase with number of files in the same directory
See original GitHub issueEnvironment
- OS Version: OSX 10.12.6
- Node.js Version: 9.50
Actual behavior
When searching for a single file (no glob parts in the path), the time increase with as the number of files in the same directory increase. With node-glob
this time is constant.
Find 1 file in a directory with 1 file (ran 500 times):
- node-glob: 48.868ms
- fast-glob: 118.218ms
Find 1 file in a directory with 500 file (ran 500 times):
- node-glob: 45.647ms
- fast-glob: 1935.108ms
Find 1 file in a directory with 2000 file (ran 500 times):
- node-glob: 48.535ms
- fast-glob: 7538.522ms
Expected behavior
Globbing a static path (with no wildcards) is a something that can happen sometimes in modules that get the glob patterns from user input, as users can pass a list of file path (e.g, mymodule file1.js file2.js file3.js
).
It seems that node-glob
has a way to detect those cases and optimize them. There is potential gain of perf in fast-glob
by implementing the same type of optimization.
Steps to reproduce
Use the code below and change the TOTAL_FILES
to measure the changes in the globbing time between fast-glob
and node-glob
.
Code sample
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const fg = require('fast-glob');
const TOTAL_FILES = 2000;
fs.mkdirSync('test')
for (let i = 0; i < TOTAL_FILES; i++) {
const filepath = path.join('test', `file-${i}`);
fs.writeFileSync(filepath, '');
}
console.time('node-glob');
for (let i = 0; i < 500; i++) {
glob.sync('test/file-1')
}
console.timeEnd('node-glob');
console.time('fast-glob');
for (let i = 0; i < 500; i++) {
fg.sync('test/file-1')
}
console.timeEnd('fast-glob');
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
I prefer solution with
is-glob
withstrict
mode. In this case we needs have a separated tasks forstatic
anddynamic
patterns (just like thedynamic
property in theITask
interface). Then, when processing a task, simply pass them to the correct adapters (fs
andreaddir-enhanced
).I’ve already started working on this issue.
Must be fixed by
fast-glob@2.1.0
. Please, read release notes for more details.Thanks for reporting ❤️!