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

Suggestion: Runtime support for faster BigInteger #97199

Open
lskyum opened this issue Jan 19, 2024 · 2 comments
Open

Suggestion: Runtime support for faster BigInteger #97199

lskyum opened this issue Jan 19, 2024 · 2 comments
Labels
area-System.Numerics tenet-performance Performance related issue untriaged New issue has not been triaged by the area owner

Comments

@lskyum
Copy link

lskyum commented Jan 19, 2024

I love C# and usually it's "fast enough" compared to lower level languages. But I have encountered a performance case, where it seems impossible to achieve even slightly comparable performance to C++ and Rust.

Some of my geometric calculations heavily relies on fractions, which I calculate with two BigInteger's. But this is relatively slow and my tests shows that this is at least x10 slower than the C/C++ library GMP and similar Rust libraries. Viewing the code for C# BigInteger, it's clear that the author is really skilled in both math and low level C# optimizations, so it's probably not possible to do any better?

There exists C# wrappers around GMP, but the overhead itself makes the performance slightly worse than just sticking with BigInteger. So my only option seems to be, to rewrite the calculations in C++ or Rust, which I really don't want to. Not only because it's tedious, but because I love C# ;-)

So the suggestion is to make BigInteger a Runtime optimized type that uses GMP (or similar) under the hood. Also the addition of a Runtime optimized BigFraction would be awesome. Obviously it will not beat C++ or Rust, but if the difference was x2 instead of x10, then it would be a game changer. It would open possibilities for making libraries like CGAL (https://www.cgal.org/) in C#.

Since I'm not a Runtime engineer I can't say if this is even possibly or how it should be done.

@lskyum lskyum added the tenet-performance Performance related issue label Jan 19, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 19, 2024
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 19, 2024
@huoyaoyuan huoyaoyuan added area-System.Numerics and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 19, 2024
@ghost
Copy link

ghost commented Jan 19, 2024

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

I love C# and usually it's "fast enough" compared to lower level languages. But I have encountered a performance case, where it seems impossible to achieve even slightly comparable performance to C++ and Rust.

Some of my geometric calculations heavily relies on fractions, which I calculate with two BigInteger's. But this is relatively slow and my tests shows that this is at least x10 slower than the C++ library GMP and similar Rust libraries. Viewing the code for C# BigInteger, it's clear that the author is really skilled in both math and low level C# optimizations, so it's probably not possible to do any better?

There exists C# wrappers around GMP, but the overhead itself makes the performance slightly worse than just sticking with BigInteger. So my only option seems to be, to rewrite the calculations in C++ or Rust, which I really don't want to. Not only because it's tedious, but because I love C# ;-)

So the suggestion is to make BigInteger a Runtime optimized type that uses GMP (or similar) under the hood. Also the addition of a Runtime optimized BigFraction would be awesome. Obviously it will not beat C++ or Rust, but if the difference was x2 instead of x10, then it would be a game changer. It would open possibilities for making libraries like CGAL (https://www.cgal.org/) in C#.

Since I'm not a Runtime engineer I can't say if this is even possibly or how it should be done.

Author: lskyum
Assignees: -
Labels:

area-System.Numerics, tenet-performance, untriaged

Milestone: -

@huoyaoyuan
Copy link
Member

See the discussion in #92184 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Numerics tenet-performance Performance related issue untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

2 participants