Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf: Pre-process extensions from files and ignores #100

Open
matwilko opened this issue Jul 13, 2023 · 1 comment
Open

Perf: Pre-process extensions from files and ignores #100

matwilko opened this issue Jul 13, 2023 · 1 comment

Comments

@matwilko
Copy link

For many configs, files patterns are likely to have an extension on the end (some form of **/*.xx or path/to/**/*.xx) in most cases.

As part of normalize, we could pre-process all the files patterns and identity the set of extensions that any file that could match must have. This could then provide a fast-path out of getConfig() by quickly eliminating any files that don't have an extension matching the known set of extensions. It could even be exposed publicly as part of the API so that they could be used to directly guide file enumeration by consumers.

There are obviously a few cases that would need to turn this fast-path off, such as functions in files, or a * pattern without an extension, but I would hope in a large number of cases (at least once flat config is more widely adopted) that this optimization would be enabled.

The same could be done for ignores, except that functions would no longer disable the optimization (since they can only ignore more files, they can't un-ignore), but care would need to be taken around negated ignore patterns.

I haven't worked out all the semantics of this yet or all the potential corner cases, but it'd be good to get your thoughts on whether it's worth it flesh this out further.

@nzakas
Copy link
Contributor

nzakas commented Jul 13, 2023

Interesting idea, but if I'm understanding correctly, it seems like the only real benefit would be when a filename that would not be matched is passed in? So if "foo.txt" is passed in and there are no patterns matching *.txt then it would exit without doing any matching?

If that's correct, then I'm not sure it's worth pursuing. The chances that the config array will be passed a filename that doesn't match any patterns is pretty slim, so we'd be optimizing a cold code path.

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

No branches or pull requests

2 participants