Suggestion: Runtime support for faster BigInteger #97199
Labels
area-System.Numerics
tenet-performance
Performance related issue
untriaged
New issue has not been triaged by the area owner
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.
The text was updated successfully, but these errors were encountered: