- Notifications
You must be signed in to change notification settings - Fork7.7k
UpdateIndexOfAny
calls with invalid path/filename toSearchValues<char>
for more efficient char searching#24896
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
UpdateIndexOfAny
calls with invalid path/filename toSearchValues<char>
for more efficient char searching#24896
Uh oh!
There was an error while loading.Please reload this page.
Conversation
IndexOfAny
calls with invalid path/filename to `SearchValues<char> for more efficient char searchingIndexOfAny
calls with invalid path/filename toSearchValues<char>
for more efficient char searching This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
@ArmaanMcleod If you share perf test results please add more information. You could put your test code under details. < /p> |
@iSazonov Please see updated description on the issue. It was a basic bench mark but it seems like substantial perf win from just a small sample. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@ArmaanMcleod Thanks for benchmark! I updated your OP to hide it under details (you can type slash |
ArmaanMcleod commentedJan 30, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Ah thanks@iSazonov . I will do that next time. Maybe we can add a section to pull request template if benchmarking results required? Might make it easier for authors to provide this for perf improvement PRs. |
iSazonov commentedJan 30, 2025 • edited by unfurl-linksbot
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by unfurl-linksbot
Uh oh!
There was an error while loading.Please reload this page.
Unfortunately, there is no constant work on performance. So there's not much point in adding this. Although if you want, you can do a PR and add the optional section in the template (with details and link(s) onhttps://github.com/PowerShell/PowerShell/tree/master/test/perf/benchmarks).
|
foreach (string segment in pathWithoutDriveRoot.Split(Path.DirectorySeparatorChar)) | ||
{ | ||
if (segment.IndexOfAny(invalidFileChars) != -1) | ||
if (PathUtils.ContainsInvalidFileNameChars(segment)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I see we never check full path so we check more short names. Could you please update perf test with loop like this (split path)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@iSazonov Yep good point. I have updated bench mark in description. I've grouped by category filename/path and params (10, 100, 1000) paths so we can bench mark small & large number of paths.
It seems pretty consistent with SearchValues outperforming IndexOfAny with char array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks! I see.
You could use[Benchmark(Baseline = true)]
so that we see Ratio column in results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@iSazonov Very nice, I think I should save this benchmark somewhere 😄.
I've updated results. Let me know if anything else is needed, I think this benchmark is quite comprehensive.
2a1d17e
intoPowerShell:masterUh oh!
There was an error while loading.Please reload this page.
microsoft-github-policy-servicebot commentedJan 30, 2025 • edited by unfurl-linksbot
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by unfurl-linksbot
Uh oh!
There was an error while loading.Please reload this page.
📣 Hey@ArmaanMcleod, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗https://aka.ms/PSRepoFeedback |
Uh oh!
There was an error while loading.Please reload this page.
PR Summary
Similar to the below PRs:
#24880
#24879
I've replaced the calls using
IndexOfAny
withPath.GetInvalidFileNameChars()
&Path.GetInvalidPathChars()
toSearchValues<char>
. I put the methods inPathUtils
which caches the search values and reuses them acrossCommandSearcher
,InitialSessionSate
,ModuleCmdletBase
andFileSystemProvider
classes.This is because these char arrays have quite a bit of characters to scan and from benchmarks it seems search values is performing a lot better as shown below in BenchmarkDotnet.
Benchmark
Details
Test Code
Results
PR Context
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).