-
Notifications
You must be signed in to change notification settings - Fork 822
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Improvements in string handling in FSharp.Core and/or FSC #9501
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
@KevinRansom (from here: #9470 (comment)) Well, the basic idea would be:
Advancing on that idea can be to replace
These last options are if we really have a need for speed, but on string-heavy implementations, these can make a real difference if applied to the right spots. These timings are of interest to this discussion: https://xoofx.com/blog/2010/10/23/high-performance-memcpy-gotchas-in-c/. That was 2010. It would be good to repeat the exercise, esp now that Of interest to the discussion of optimizing copying of memory will be my next PR on |
Okay, by writing unsafe code. I was hoping you knew of some magic way of not doing it that way 😊
|
@KevinRansom: your whole mail includes a copy of the prev. message with outlook links etc...
I do, in a way, but that's another technique we can only use outside of FSharp.Core. It uses a simple trick to change the let spanCopy (mapper: char -> char) (str: string) =
let len = String.length str
let resultStr = String.Copy str
let roSpan = str.AsSpan()
let writeSpan = MemoryMarshal.CreateSpan(&MemoryMarshal.GetReference roSpan, len)
let mutable i = 0
while i < len do
writeSpan.[i] <- mapper roSpan.[i]
i <- i + 1
resultStr And there's of course Though, I am not quite sure why the persistence against using of |
My comment from the PR (#9470) and removed there (makes more sense here): @KevinRansom From our sessions and timings, I think we can agree that if the target string-size is known, using For now, alternatives with Furthermore, SB, buffered or not, doesn't help here because of the added overhead per iteration. Though I reckon there will be cases where the buffered SB will help, perhaps with
We may find places in FSC that are amenable to better optimizations w.r.t. string or array allocations. Finding the right spots will be the difficult bit though. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem?
Strings are omnipresent and recent discussions and profiling have shown that improvements can be made here that may be applicable to other parts of the ecosystem.
I've created this issue to discuss some options.
StringBuilderCache
: String map performance improvement #9470 (comment) and String map performance improvement #9470 (comment)Describe the solution you'd like
Several options have come forward and are up for discussion:
StringBuilder
is used and investigate if improvements are viable withStringBuilderCache
(currently private in BCL, uses thread-local storage)ArrayPool
, possibly cherry-picking fromSystem.Buffer
. The advantage here is that zeroing of memory is skipped. This cannot be used for shared instances of SB or strings.ReadOnlySpan
and/orString.Create
can help. This is .NET Standard 2.1, so we can only do that in FCS and tooling, I thinkfixed
, similar to how BCL does it. For string scenarios this can bring pressure down by 2x.ArrayPool
technique and/or by speeding up array creation and copying in scenarios similar toArray.map/collect
.cpblk
orinitblk
in certain scenarios. These have recently been highly improved in the CLRAdditional context
My idea is to discuss/brainstorm perf ideas (please check the prev. discussions) and the scope and then, where applicable, use separate issues for defined targets. One I've been working on silently has been
Array.xxx
functions, which are already highly optimized, but some measurements suggest there's room for further improvement.The text was updated successfully, but these errors were encountered: