-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
math/big: printing is non-linear and very slow for large Floats #11068
Comments
Work around Go issue golang/go#11068 It won't run if you've set a custom format - maybe we can handle that in another round - but it makes a huge difference. Big ints are unaffected.
Analysis: For large exponents, the decimal conversion creates the exact binary value in "full precision", which is then converted into a decimal string at decimal.go:75 by calling m.decimalString(), and then rounded to the desired number of decimal digits. For large positive exponents, most of the time is spent in this function (natconv.go:240) and eventually in nat.string (natconv.go:253). Here's a small driver function to call the involved routines and expose the behaviour:
When the number of desired digits is small and exponents large, we should avoid this conversion path. |
From e-mail thread: here is an idea about how to do the floating point prints more this code works but is missing many important properties, such as -rob
|
A more thorough implementation is now in robpike.io/ivy/value/bigfloat.go in the dev branch. It is fairly well tested and is now used by ivy for any value with huge exponents. |
What's the status here? Is something happening or should we punt this to Go 1.7? |
Not addressed yet. I think it's a localized fix, but subtle to get right.
On Wed, Dec 9, 2015 at 7:43 AM, Brad Fitzpatrick [email protected]
|
Started. |
for 1e50000 this takes 3 ms, for 1e500000 - 282 ms and for 1e5000000 - 37 seconds. (I get the same times if I convert the big.Int to a big.Float and print that.) |
@realityexists not really. A The problem with |
Yes, 1e5000000 is has 5 MB of zeros, but I would not expect that to take 37 seconds to generate. Anyway, the times are almost identical for Int and Float, which leads me to believe the cause is probably the same. |
But you'd expect the times to grow exponentially, right? The size in memory of a
That's because -as Robert wrote above- we go through decimal conversion with too many digits, and decimal conversion is slow. The proposed fix is to not do that. I agree that |
I don't know exactly how
Ah, I missed that - thanks for pointing it out. So perhaps |
yeah sorry, brain fart. You're right. In any case, you're also right when you say it's slow, I'll open another issue for the slow |
The Text method of big.Float produces a textual representation of the floating point number. I have a program that can create very large numbers and they are slow to print. Moreover, the time to print them does not scale sensibly with the size of the number:
% time ivy -e '1e10000' > /dev/null
real 0m0.005s
user 0m0.002s
sys 0m0.003s
% time ivy -e '1e100000' > /dev/null
real 0m0.032s
user 0m0.027s
sys 0m0.004s
% time ivy -e '1e1000000' > /dev/null
real 0m2.729s
user 0m2.702s
sys 0m0.017s
% time ivy -e '1e10000000' > /dev/null
real 7m11.246s
user 7m7.678s
sys 0m1.834s
%
I have investigated to some extent and the time is definitely being spent inside Text.
The text was updated successfully, but these errors were encountered: