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

[C#] Optimize memory allocations when parsing numbers in .NET5 or greater #16034

Conversation

TrayanZapryanov
Copy link
Contributor

Do not use StringBuilder when loading and parsing numbers by using char buffer.
If target is NET5 or greater stackalloc can be used, but due to compatibility reasons we cannot use some Span<> methods.

@TrayanZapryanov TrayanZapryanov requested a review from a team as a code owner March 4, 2024 15:43
@TrayanZapryanov TrayanZapryanov requested review from jskeet and removed request for a team March 4, 2024 15:43
@jskeet
Copy link
Contributor

jskeet commented Mar 4, 2024

Again, I'm not going to have time to get to this any time soon.

@jskeet
Copy link
Contributor

jskeet commented Mar 4, 2024

This will conflict with #15794. Do you want me to go ahead getting a final review for that and getting that merged, or is this your preferred approach now?

@TrayanZapryanov
Copy link
Contributor Author

Again, I'm not going to have time to get to this any time soon.

No worries. Do it once you have time.

@TrayanZapryanov
Copy link
Contributor Author

This will conflict with #15794. Do you want me to go ahead getting a final review for that and getting that merged, or is this your preferred approach now?

Please review and merge the other one first. This one will be adapted after that.

@TrayanZapryanov
Copy link
Contributor Author

Same benchmark as here

Main
// * Summary *

BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3235/23H2/2023Update/SunValley3)
11th Gen Intel Core i9-11900K 3.50GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK 8.0.200
[Host] : .NET 8.0.2 (8.0.224.6711), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
DefaultJob : .NET 8.0.2 (8.0.224.6711), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI

Job=DefaultJob Error=3.84 ns StdDev=3.21 ns

Method Mean Allocated
Small 281.1 ns 1.01 KB
Big 256,221.4 ns 642.7 KB

PR
Optimize number

Method Mean Allocated
Small 264.0 ns 936 B
Big 260,213.7 ns 564016 B

@jskeet
Copy link
Contributor

jskeet commented Mar 22, 2024

Please could update this in light of the current HEAD? I can then try to take a look next week.

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

Successfully merging this pull request may close these issues.

2 participants