-
-
Notifications
You must be signed in to change notification settings - Fork 741
Minimize use of GC for doubles in printFloat. #7767
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
Conversation
Thanks for your pull request and interest in making D better, @berni44! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#7767" |
@@ -8448,7 +8448,7 @@ printFloat_done: | |||
import core.memory; | |||
auto stats = GC.stats; | |||
|
|||
char[256] buf; | |||
char[512] buf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this, because the call in formatValueImpl
also provides a buffer with 512 chars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan on making printFloatE completely @nogc
?
@@ -7754,7 +7754,7 @@ if (is(T == float) || is(T == double) || (is(T == real) && T.mant_dig == double. | |||
// digits. If still necessary, we decide the rounding type, mainly by looking at the | |||
// next digit. | |||
|
|||
ulong[4] bigbuf; | |||
ulong[18] bigbuf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N00b question: why 18?
@@ -7764,7 +7764,7 @@ if (is(T == float) || is(T == double) || (is(T == real) && T.mant_dig == double. | |||
int count = exp / 60 + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that the value of count cannot ever be greater than 18?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. For float it cannot be greater than 3 and for double it cannot be greater than 18. (exp is maximum 127/1023).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if in the future we could get rid of allocations for the entire function and maybe introduce a @nogc
unittest.
This will be hard to achieve this goal and might reduce the speed considerably. The reason is, that the output could be arbitrarily large (in theory). To make this Processing from left to right involves a BigInt multiplication with a large and a very large number. When not using If you wonder where's the difference between |
A fixup for #7393. Now it's guaranteed, that printing float and double with %a or %e will not use gc as long as the output is restricted to 500 characters. (Without this change, this guarantee did only hold for floats but not for doubles.)