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

Faster EnumCaseObjectType->describe() #3208

Closed
wants to merge 2 commits into from
Closed

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 3, 2024

repro of phpstan/phpstan#11263 before this PR

php bin/phpstan analyze slow.php --debug
  7.16s user 0.14s system 99% cpu 7.323 total

php bin/phpstan analyze slow.php --debug
  7.18s user 0.13s system 99% cpu 7.339 total

after this PR:

php bin/phpstan analyze slow.php --debug
  5.29s user 0.14s system 99% cpu 5.478 total

php bin/phpstan analyze slow.php --debug
  5.25s user 0.14s system 99% cpu 5.403 total

@staabm staabm marked this pull request as ready for review July 3, 2024 07:10
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm
Copy link
Contributor Author

staabm commented Jul 3, 2024

do you think we are fast enough to add a regression test for the bug and call it a day?

if (!array_key_exists($value, $this->descriptions)) {
$this->descriptions[$value] = sprintf('%s::%s', parent::describe($level), $this->enumCaseName);
}
return $this->descriptions[$value];
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it make sense to cache this in the parent instead? In ObjectType

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it also works. it makes the repro 0,2-0,3 seconds slower though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved the cache into ObjectType.

feel free to close this PR, in case it no longer serves a purpose.

@ondrejmirtes
Copy link
Member

FYI I have a local branch where the reproduction takes zero zero nothing seconds, I "just" need to make it fully work. So any further optimizations from you that shave off percents from the time are in the negligible returns territory. Stay tuned! :)

@staabm
Copy link
Contributor Author

staabm commented Jul 3, 2024

Thats great news 💪

@ondrejmirtes
Copy link
Member

@staabm I'm going to test it after my change. The previous PRs made sense on their own, but here we are adding caches (which means more memory consumed) so let's wait if it's still worth it.

@staabm staabm deleted the faster branch July 3, 2024 11:39
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