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

fix: avoid globbing non-dynamic paths #121

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

Conversation

SuperchupuDev
Copy link

fixes #119

the problem with glob usage in this project is that globSync is called multiple times which isn't optimal, as it forces tinyglobby to traverse the filesystem multiple times. in theory, globSync could be called just once during the walking process, but that would be a bigger refactor, although a possible one

it looks like under a default config most patterns passed to globSync aren't even globs, so this PR avoids unnecessary globSync calls when none of the patterns are globs

screenshot of patterns passed to tinyglobby in 6.1.0, each log is a different glob call

image

locally (windows) this change makes it faster than 5.15.0, with the reproduction from #119 taking 25s in 5.15.0 and 13s in latest with the change (latest without the change took too long to measure)

@SuperchupuDev
Copy link
Author

ci is failing, will debug tomorrow

@robertsLando
Copy link
Member

robertsLando commented Nov 5, 2024

Could you also test if there are improvements with the test-80-compression-node-opcua test? It actually takes 5 min on ubuntu to complete.

Seems now it went down to 2min: https://github.com/yao-pkg/pkg/actions/runs/11675697212/job/32510712730?pr=121#step:7:20 :) I think there is still range of improvement here. Could you try enabling that test also for windows and mac?

Just remove this lines:

// FIXME: this test takes a long time to run (from 5min on linux up to 10 minuntes on windows)
// run only on linux to save time on CI
if (process.platform !== 'linux') {
return;
}

@robertsLando robertsLando changed the title avoid globbing non-dynamic paths fix: avoid globbing non-dynamic paths Nov 6, 2024
@robertsLando
Copy link
Member

I also created #122, I would like to compare performances of tests in this two PR

@SuperchupuDev
Copy link
Author

from my local tests in the zip repro of #119 this should be faster than #122, since the unnecesary glob calls were still present back then

@robertsLando
Copy link
Member

In fact seems this is faster 👍🏼

Comment on lines +202 to +213
if (isDynamicPattern(pattern)) {
patterns.push(pattern);
} else if (existsSync(pattern)) {
paths.push(pattern);
}
}

if (patterns.length !== 0) {
return [...paths, ...globSync(patterns, { absolute: true, dot: true })];
}

return paths;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why tinyglobby cannot use isDynamicPattern his own by default before starting parsing a pattern?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency shenanigans, but mainly just that i don't think it will be needed once its optimization pr gets fixed and lands

@SuperchupuDev
Copy link
Author

okay i see why at least some tests fail, it's due to this project using directory expansion, which means that globbing dir is the same as globbing dir/**. dir itself is technically not dynamic so it gets skipped which shouldn't happen

@robertsLando
Copy link
Member

@SuperchupuDev Yep understood, could you fix that?

@SuperchupuDev
Copy link
Author

trying

@SuperchupuDev
Copy link
Author

SuperchupuDev commented Nov 6, 2024

okay, fixing it would just make all patterns dynamic, making performance not change whatsoever. we need a better solution. there needs to be a refactor in the walker logic so that all patterns are pushed into an array and then when all of them are collected call globSync once

@robertsLando
Copy link
Member

@SuperchupuDev Makes sense, agreee

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.

Slow packaging of pnpm workspaces project
2 participants