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

Small performance optimizations #83

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Torathion
Copy link

Hi, I wanted to contribute to this amazing project and came across some tiny performance optimizations that could be made. I tried not to change too much code or break your coding style. Those are very minor changes that only benefit projects and tools processing a large number of paths and globs.

The PR mainly focuses on stabilizing the performance by:

  • inlining unnecessary variables
  • reducing overhead by reducing the number of object property calls like .length or .root
  • avoiding accidental duplicate calculations like the windows platform check or the loop length of the pattern normalization
  • changing the fdir path transformation from creating a new array via map to transforming it in-place

Also, tinyglobby is now ~25 bytes smaller.

Copy link

pkg-pr-new bot commented Jan 22, 2025

Open in Stackblitz

npm i https://pkg.pr.new/tinyglobby@83

commit: 7a1d49c

@Torathion
Copy link
Author

Sorry for the extra linting commits. Biome doesn't work on my machine.

@SuperchupuDev
Copy link
Owner

interesting, i do value performance over code style, but i'd like to first check if this makes any meaningful perf improvement, the vast majority of the glob time in general is spent doing I/O i think which is the area that could benefit the most from optimizations. i'll check this out in more detail later, there's some work i need to do first. thanks for the effort!

@Torathion
Copy link
Author

I tested it with your test fixture and it roughly was the same performance, but my version was more stable in terms of performance, so I do believe you see the greater benefit if you create a fixture with a ton of files and glob patterns, because I only adjusted the performance inside loops.

I'm also still trying to figure out an alternative to posix.relative as you mentioned the performance issues inside your code. But since path.relative and path.posix.relative have a different behavior, I wait until you fixed the windows parsing issues for me to experiment.

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

Successfully merging this pull request may close these issues.

2 participants