Skip to content

Remove unnecessary file IO - #2069

Merged
ondrejmirtes merged 1 commit into
phpstan:1.9.xfrom
staabm:fileio
Dec 9, 2022
Merged

ondrejmirtes merged 1 commit into
phpstan:1.9.xfrom
staabm:fileio

Conversation

@staabm

@staabm staabm commented Dec 9, 2022

Copy link
Copy Markdown
Contributor

remove file IO when not necessary. the IO subsystem can be super slow or at least performance can vary a lot dependent on when/where you read data from

grafik

return null;
}

$cacheItem = @include $filePath;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

since we already swallow possible errors and validate the result we read just after that, we don't need to check beforehand whether $filePath actually is a file.

$filename = $this->declaringTrait->getFileName();
}

if (!$isNativelyVariadic && $filename !== null && is_file($filename)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

filemtime will return false when $filename is not a file. the code already handles this case.

lets drop this unnecessary file IO

@staabm
staabm marked this pull request as ready for review December 9, 2022 15:54
@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes

Copy link
Copy Markdown
Member

What's the command you're profiling this with?

@staabm

staabm commented Dec 9, 2022 •

Copy link
Copy Markdown
Contributor Author

blackfire run php bin/phpstan -vvv --debug

it is compared against phpstan 1.9.x @ da8413c

@ondrejmirtes
ondrejmirtes merged commit 062c456 into phpstan:1.9.x Dec 9, 2022
@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you!

@staabm
staabm deleted the fileio branch December 9, 2022 16:16
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