Skip to content

Optimize path related utils on windows - #2068

Merged
ondrejmirtes merged 6 commits into
phpstan:1.9.xfrom
staabm:fast-normalize
Dec 10, 2022
Merged

ondrejmirtes merged 6 commits into
phpstan:1.9.xfrom
staabm:fast-normalize

Conversation

@staabm

@staabm staabm commented Dec 9, 2022 •

Copy link
Copy Markdown
Contributor

the changes mainly prevent excessive use of PCRE on windows. this leads to a small performance improvement of ~3%.

more suprising is blackfire reporting a 56% improvement on memory usage (830 MB instead of 1.9 GB).

grafik

tested on windows 11

php -v
PHP 8.1.2 (cli) (built: Jan 19 2022 10:13:52) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with blackfire v1.76.0~win-x64-non_zts81, https://blackfire.io, by Blackfire

Comment thread src/Type/FileTypeMapper.php Outdated

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.

moved this normalization below the early return, to prevent unnecessary work

Comment thread src/File/FileHelper.php Outdated

@staabm staabm Dec 9, 2022 •

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.

on windows we now take this fast path and prevent PCRE usage for regular paths starting with C:\\

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about other drive letters?

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.

are you "ok" with allowing any uppercase character?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, but I feel like there has to be a better way other than comparing letters as if they were numbers :)

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.

wdyt about using ord()? :)

to be honest, I don't like both ways. using regex would work, but we wanne be fast, right? :)

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.

ok, another idea. now using range()

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

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

Comment thread src/File/FileHelper.php Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about other drive letters?

@staabm
staabm force-pushed the fast-normalize branch 4 times, most recently from e8120e9 to da764b1 Compare December 10, 2022 09:16
@staabm

staabm commented Dec 10, 2022 •

Copy link
Copy Markdown
Contributor Author

@ondrejmirtes any reasons this was not merged yet? the memory improvement is even more valuable then the time improvement IMO (less likely the process needs to go to swap)

@ondrejmirtes

Copy link
Copy Markdown
Member

I think you're overthinking it - what about not checking the letter at all and just checking that 2nd and 3rd character is :\ ?

@staabm

staabm commented Dec 10, 2022

Copy link
Copy Markdown
Contributor Author

I am fine with that, too. here we go.

@ondrejmirtes
ondrejmirtes merged commit d00f0de into phpstan:1.9.x Dec 10, 2022
@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you!

@staabm
staabm deleted the fast-normalize branch December 10, 2022 12:22
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