question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Time to find a non glob path increase with number of files in the same directory

See original GitHub issue

Environment

  • 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:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mrmlnccommented, Feb 15, 2018

I prefer solution with is-glob with strict mode. In this case we needs have a separated tasks for static and dynamic patterns (just like the dynamic property in the ITask interface). Then, when processing a task, simply pass them to the correct adapters (fs and readdir-enhanced).

I’ve already started working on this issue.

1reaction
mrmlnccommented, Feb 25, 2018

Must be fixed by fast-glob@2.1.0. Please, read release notes for more details.

Thanks for reporting ❤️!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use glob to read limited set of files with numeric names?
The crucial line here (should) iterate through each file name in the directory ( for this_file in all_files ), pull out a list...
Read more >
Python Glob: Filename Pattern Matching - PYnative
Python glob module to find files and folders whose names follow a specific pattern. Search files recursively with wildcard characters.
Read more >
How can I get a count of files in a directory using the command ...
If you know the current directory contains at least one non-hidden file: set -- *; echo "$#". This is obviously generalizable to any...
Read more >
How to use Glob() function to find files recursively in Python?
We can use the function glob.glob() or glob.iglob() directly from glob module to retrieve paths recursively from inside the directories/files ...
Read more >
Python's Glob Module: A tutorial for filename matching
First, we can use glob to find all files in a directory and its ... Searching a large number of directories could take...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found