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

CachedParser: use LRU cache #2879

Closed
wants to merge 3 commits into from
Closed

Conversation

janedbal
Copy link
Contributor

@janedbal janedbal commented Jan 17, 2024

No description provided.

@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x.

@janedbal janedbal changed the base branch from 1.11.x to 1.10.x January 17, 2024 11:10
src/Parser/LRUCache.php Outdated Show resolved Hide resolved
@staabm
Copy link
Contributor

staabm commented Jan 17, 2024

But the time difference is unmeasurable here. Who knows if some codebase with complex huge files might cause measurable differences or not.

did you compare before and after with the lowered capacity?
Did you have a look at memory consumption of both impls?

@janedbal
Copy link
Contributor Author

Did you habe a look at memory consumption of both impls?

Only by seeing what PHPStan reports in -vvv mode. No changes.

Did you compare before and after with the lowered capacity?

PHPStan itself uses lowered capacity (128 instead of default 256) and that is what I tested (results above). I did not do any tests on our huge codebase yet.

@staabm
Copy link
Contributor

staabm commented Jan 17, 2024

Yeah… my point was more about: in case we can reduce the capacity of the cache with this PR, it might be useful because even if it is equal fast, it might save memory

{

/** @var array<string, TValue> */
private array $cache;
Copy link
Contributor

Choose a reason for hiding this comment

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

it might make sense to try SplFixedArray here

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm our capacity is too small for it beeing useful

https://stackoverflow.com/a/11831076

@janedbal janedbal marked this pull request as draft January 17, 2024 14:17
@janedbal
Copy link
Contributor Author

After all, it seems like time & cache-miss & memory difference is very small.


So the only benefit of this MR might be the code readability & test improvement. I can replace the LRUCache with old logic. Would you merge it after that @ondrejmirtes? Or just close it.

@ondrejmirtes
Copy link
Member

Yeah, I don't think this fixes a real problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants