Skip to content

Conversation

@MichaONO
Copy link
Contributor

Many possible locations for the patchwork.json were checked repeatedly, now they should only be checked once. This gave me a nice speedup. So hopefully this does not break anything and is helpful for others as well.

Copy link
Collaborator

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me, save a bunch of is_file() calls. Some minor comments inline.

src/Config.php Outdated
while (dirname($path) !== $path) {
$file = $path . DIRECTORY_SEPARATOR . FILE_NAME;
if (is_file($file) && !isset($alreadyRead[$file])) {
if (!array_key_exists($file, $alreadyRead) && is_file($file))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Completely personal preference, but when I see array_key_exists() I start looking for the array to contain null values. That's not the case here, so I'd personally stick with isset().

I might also rename $alreadyRead to $alreadyChecked, since the files aren't necessarily read anymore.

I wonder if it would make a measurable difference to take this even further with something like

// If we've already checked this file, then we've already checked everything above it too.
if (isset($alreadyChecked[$file]))) {
    break;
}
$alreadyChecked[$file] = true;

if (is_file($file)) {

OTOH, the rest of the loop may be so fast now that it doesn't matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your comments!

I personally prefer array_key_exists() as isset() feels to me like it would try to access a non-existing value and then fail and catch an error, but afaik that is not what is actually happening. However I prefer the readability of isset() as it is really clear what is the array and what is the key. So I just changed it. I also thought about using the null coalescing oeprator, which I think could also be a conceptually clean solution, but the readability is even worse.

On my first attempt I wanted to keep the number of changed lines so and that is why I didn't change the name of the array. And also for some reason I didn't come up with a name I liked, but I like your suggestion.

I did not implement the "early stopping" as at least on my test system is_file() is so much slower than everything else that in my opinion it is not worth the additonal code.

Sorry that it took me so long to reply, there was just too much other stuff going on.

@anomiex anomiex merged commit 4cecc74 into antecedent:master Apr 21, 2025
10 checks passed
@jrfnl jrfnl added this to the 2.2 Next milestone Aug 11, 2025
@jrfnl jrfnl modified the milestones: 2.2 Next, 2.2.2 Sep 17, 2025
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.

3 participants