-
Notifications
You must be signed in to change notification settings - Fork 5k
Potential optimizations for System.IO.Path #18223
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
Comments
Personally I'd like to remove the path char check- perhaps under an AppContext switch. It isn't that useful- on Unix it's just "no nulls". Additionally it isn't technically correct for all Windows paths (notably pipes)- I skip it entirely with device paths because of this. You may want to consider looking at how StringBuffer performs compared to StringBuilder since were already using it and it's cached. |
Regarding AppContext itself, what would be the overhead of using that? AFAICS it does locking which could be relatively expensive.
Seems like an interesting option. I'm going to hazard a guess that simply having a I think the best strategy would be to do something like |
@JeremyKuhne I found something unexpected after running 1m iterations of Proof: The main bottleneck in there appears to be this method, which initializes a bitmap of some sort to indicate whether a character is in the array. It grows in complexity for each char in the array, so due to the huge amount of invalid chars in Windows it's taking up a lot of time. |
@jamesqo The desktop implementation uses Interlocked.Exchange. @AlexGhiondea, any plans to optimize AppContext? Most of the characters are < (char)32. All of which are pretty unlikely. Outside of that you only have 4 chars. Walking through the string manually would likely give better results. |
AppContext does lock, but it should only take the lock once per app domain per switch. Once the value of the switch is retrieved, it is cached and no further locks are taken for retrieving the value. @JeremyKuhne did you have an optimization in mind? |
@JeremyKuhne I moved this to Future as it does not seem necessary for 2.0 |
Much of this implementation has changed, e.g. IndexOfAny has changed its implementation completely, Path has been optimized in a variety of ways, etc. To do anything here would require a complete re-investigation to see what the bottlenecks are and whether they actually matter. As such, I'm closing this as inactionable. Please feel free to open a new issue if other real problems are found. Thanks. |
CheckInvalidPathChars
is called as much as 1-3 times in most Path chars, however due to all of the exception-throwing code it doesn't look as if it's going to be inlined. SInce Do not inline methods that never return coreclr#6103 was merged, it may be beneficial to separate the throwing logic out to encourage inlining, for example:ToString
and indexing into that instead.StringBuilder.Append(char)
is inlined, and we could use achar[]
instead since we know the max length of the buffer in advance.ArrayPool<char>.Shared.Rent
, instead of usingStringBuilder
?cc @JeremyKuhne
The text was updated successfully, but these errors were encountered: