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

Make FileRequired faster by using HasSuffix instead of filepath.Base #440

Open
vpasdf opened this issue Feb 5, 2025 · 0 comments
Open

Comments

@vpasdf
Copy link
Collaborator

vpasdf commented Feb 5, 2025

The path in FileRequired has / even on windows. This is because the walk function uses path.Join.
http://google3/third_party/scalibr/extractor/filesystem/internal/walkdir_iterate.go;l=73;rcl=680571378

Using HasSuffix is O(len(suffix)) rather than O(len(path)) for filepath.Base.

path usually does not have a / prefix. So 1:1 replacement of filepath.Base(p) == x to strings.HasSuffix(p, x) won't work. But something like strings.HasSuffix("/"+p, x) could work. It's unclear how much the string concatenation costs.

This needs more benchmarking and one refactoring of the code base.

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

No branches or pull requests

1 participant