Merged
Conversation
mvorisek
reviewed
May 16, 2025
| return Strings::match(ltrim($name, '\\'), '/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*(\\\\[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)*$/') !== null; | ||
| if (!array_key_exists($name, self::$checked)) { | ||
| // from https://stackoverflow.com/questions/3195614/validate-class-method-names-with-regex#comment104531582_12011255 | ||
| self::$checked[$name] = Strings::match(ltrim($name, '\\'), '/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*(\\\\[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)*$/') !== null; |
Contributor
There was a problem hiding this comment.
How much faster https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.75.0/src/DocBlock/TypeExpression.php#L177-L179 this regex is using native preg_match directly?
Regexes are usually fast.
(...*)* in theory can be very slow compared to (...*+)*.
Also the trim can be easily integrated into the regex (and as the linked PHP CS Fixer already does).
And the main slowdown seems to be comming from Nette. As long as the regex is valid, no need to check for anything else than the return value. This is what PHPStan already checks and check well.
Member
|
Awesome, thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
70% faster edge case in
vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php --filter testBug10979- which is currently the slowestAnalyserIntegrationTestin the repo.Before this PR
After this PR
Profile before the PR
triggered on
IntersectionType->getFiniteTypes()