-
Notifications
You must be signed in to change notification settings - Fork 831
Closed
Labels
Milestone
Description
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.
- Several string-related timings: Performance of certain build-in functions, esp the ones related to Array manipulation #9390.
- Discussion with @KevinRansom on applying this broader: String map performance improvement #9470
- Comment with timings on
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:
- Find cases where
StringBuilderis used and investigate if improvements are viable withStringBuilderCache(currently private in BCL, uses thread-local storage) - Where heavy string-copying is used locally, investigate use of
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. - On hot paths, check if using
ReadOnlySpanand/orString.Createcan help. This is .NET Standard 2.1, so we can only do that in FCS and tooling, I think - Where high GC pressure and/or LOH pressure is recognized we should perhaps consider using
fixed, similar to how BCL does it. For string scenarios this can bring pressure down by 2x. - Use techniques shown in Performance of certain build-in functions, esp the ones related to Array manipulation #9390 with fixed-size char-arrays, possibly further improved with array pools.
- Improve array manipulations by dipping into the
ArrayPooltechnique and/or by speeding up array creation and copying in scenarios similar toArray.map/collect. - Investigate if we can use
cpblkorinitblkin certain scenarios. These have recently been highly improved in the CLR - Perhaps look into ZString, some techniques there (pooling, zero-allocation strings) may be helpful: https://github.com/Cysharp/ZString
Additional 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.