Skip to content

[Filesystem] Cache more calls in Path #58890

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

Closed
Toflar opened this issue Nov 15, 2024 · 5 comments
Closed

[Filesystem] Cache more calls in Path #58890

Toflar opened this issue Nov 15, 2024 · 5 comments
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Filesystem

Comments

@Toflar
Copy link
Contributor

Toflar commented Nov 15, 2024

Description

In our project, we use Path::makeRelative() quite extensively. In 90% of all cases $basePath is identical. But still, Symfony calls self::split($basePath) on this on every single call wasting lots of resources.

We already cache the results of canonicalize() in $buffer with some $bufferSize "magic". Before creating a PR, I wanted to ask which way we should go here. There's actually a lot that could be cached in this utility class. Who defines which methods qualify for a static buffer?

And is that buffer handling even the correct approach? Should't we have a static reset() or so? Should the existing filesystem service call Path::reset() then?

Wdyt?

Example

No response

@xabbuh xabbuh added the DX DX = Developer eXperience (anything that improves the experience of using Symfony) label Nov 16, 2024
@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@Toflar
Copy link
Contributor Author

Toflar commented May 19, 2025

No unfortunately it has not been resolved. I would be happy to work on a PR but I want to know the path forward so I guess whoever would have merge-power for a PR against the filesystem component would need to give feedback on may strategic questions (what can be cached and how do we reset?).

@carsonbot carsonbot removed the Stalled label May 19, 2025
@GromNaN
Copy link
Member

GromNaN commented May 19, 2025

You can start by creating a performance benchmark, using phpbench. Then you identify the slow parts and work on optimization and caching, in this order. We truly appreciate having the benchmark results before and after the change, as part of the pull request description.

And is that buffer handling even the correct approach? Should't we have a static reset() or so? Should the existing filesystem service call Path::reset() then?

The buffer system prevent memory leaks as there is limit in the number of items.

@Toflar
Copy link
Contributor Author

Toflar commented May 19, 2025

The buffer system prevent memory leaks as there is limit in the number of items.

Yes, of course. The question was more if we should keep that because we basically have this nowhere else in Symfony. Maybe I'll just do a proposal then.

@Toflar
Copy link
Contributor Author

Toflar commented May 21, 2025

I tried using phpbench and blackfire but I was unable to find a way to improve this. I mean there is a benefit when caching for sure but it's so marginal that building a proper static getFromCache() function or so and calling that creates more overhead than doing the split() 10_000 times on the same string.

@Toflar Toflar closed this as completed May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Filesystem
Projects
None yet
Development

No branches or pull requests

4 participants