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

Unify CoreLib/System.Runtime.Numerics formatting/parsing code #28657

Open
stephentoub opened this issue Feb 8, 2019 · 14 comments
Open

Unify CoreLib/System.Runtime.Numerics formatting/parsing code #28657

stephentoub opened this issue Feb 8, 2019 · 14 comments
Labels
area-System.Numerics Cost:M Work that requires one engineer up to 2 weeks help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@stephentoub
Copy link
Member

Once upon a time it seems as though System.Runtime.Numerics forked the integer formatting/parsing code that's in CoreLib. That CoreLib code has since evolved, and is also now being mirrored to corefx, where System.Runtime.Numerics could include it rather than maintaining its own copy.

cc: @tannergooding

@nabeelvalley
Copy link
Contributor

Hi, is this still open? What's needed on this?

@stephentoub
Copy link
Member Author

is this still open?

Yes

What's needed on this?

The file
https://github.com/dotnet/corefx/blob/master/src/Common/src/System/Globalization/FormatProvider.Number.cs
is now a stale copy of https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/Number.Formatting.cs
though there's likely some functionality in the former that no longer exists in the latter but that's still needed for BigInteger.

The work here is to rationalize the difference and get to a point where the System.Runtime.Numerics library (which is currently including the former) can instead include the latter, and do so without negatively impacting the performance of code currently using the latter.

@danmoseley
Copy link
Member

@nabeelvalley want to take a shot at this work?

@nabeelvalley
Copy link
Contributor

@danmosemsft / @stephentoub I'd like to look at it, still a little unclear about what exactly is needed though, and also what background knowledge/info would I need to work on this?

@danmoseley
Copy link
Member

@nabeelvalley its pretty much what's described above. You could take a look at the code mentioned maybe.

For a first contribution though, you could look at a smaller change if you want to ? There are a lot of issues marked "up for grabs" you could choose from.

@nabeelvalley
Copy link
Contributor

Hi @danmosemsft , thanks, I've taken a look and it seems a bit out of my depth at the moment, but I will look at what else is around

@danmoseley
Copy link
Member

@nabeelvalley ok, not a problem, hope to see you elsewhere in the repo!

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 5.0 milestone Feb 1, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@tannergooding tannergooding added area-System.Numerics and removed area-System.Runtime untriaged New issue has not been triaged by the area owner labels Jun 23, 2020
@ghost
Copy link

ghost commented Jun 23, 2020

Tagging subscribers to this area: @tannergooding
Notify danmosemsft if you want to be subscribed.

@tannergooding tannergooding modified the milestones: 5.0.0, Future Jun 23, 2020
@ViktorHofer
Copy link
Member

@stephentoub is that still the case with the consolidated repo?

@stephentoub
Copy link
Member Author

Yup

@tannergooding tannergooding added the Cost:M Work that requires one engineer up to 2 weeks label Jan 15, 2021
@huoyaoyuan
Copy link
Member

Looking at this. Number is using a lot of CoreLib internals. Though many of them isn't required by System.Runtime.Numerics, it isn't factored to be included only a part. Some others like FastAllocateString are critical to performance.
Folding it into CoreLib doesn't sound correct to me. @stephentoub any thoughts here?

@huoyaoyuan
Copy link
Member

It does help a lot to fold into CoreLib, but it doesn't sound correct that anything numeric related are required to be in CoreLib to get best performance.

Currently blockers to compile Number out of CoreLib:

  • FastAllocateString. How does ValueStringBuilder perform comparing to it?
  • Decimal/Half manipulating. Can become public API, or use reinterpret cast.
  • NumberFormatInfo internals. They are all available through public API, however those APIs has to defensive copy for array-returning members.
    • This also means that any third-party library can't utilize NumberFormatInfo with good performance

@stephentoub
Copy link
Member Author

anything numeric related are required to be in CoreLib to get best performance

It is likely always going to be the case that internal implementation details of corelib can be utilized to eek out the best perf. For example, you mention FastAllocateString: that will never be exposed publicly, because it's an implementation detail of creating a mutable System.String that's written to and then published for immutable consumption. The public version of that is String.Create, which enables the same functionality but in a safe, span-based manner, the primary overhead of which is an extra delegate invocation.

it isn't factored to be included only a part

Work here could include refactoring to split the file into pieces compiled into both assemblies and pieces that are unique to one or the other. It could also (if feasible) involve changing portions of the BigInteger code to sit on top of public API instead where that's possible functionally and without significantly impacting performance.

@huoyaoyuan
Copy link
Member

Yep. After looking a bit more, the only required thing is NumberFormatInfo. It's API shape is unfriendly for performance, and the number formatting code access internal fields directly to avoid defensive copy. I think it's better to open a new issue for discussing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Numerics Cost:M Work that requires one engineer up to 2 weeks help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

8 participants