-
-
Notifications
You must be signed in to change notification settings - Fork 707
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
Draft: Reduce template bloat in std.format #8247
Conversation
Thanks for your pull request and interest in making D better, @nordlow! 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#8247" |
3887e77
to
f30f22a
Compare
Irrespective of the memory gains, I think that having the parameter to format being |
286debc
to
9f75cdc
Compare
|
||
void formatValueImplBool(Writer, Char)(auto ref Writer w, const(bool) val, scope const ref FormatSpec!Char f) |
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 fail to understand how factoring code out into a new template declaration reduces template bloat
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.
Oh, I understand now. Code that is the same for each template instance should be factored out so that the generated code is smaller.
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.
Honestly, I think that such optimizations should be benchmarked on their own. It is hard to assess the impact of this optimization when it is bundled with others. I suggest splitting this PR into different ones and assess the gains on their own. There must be a proven benefit to accept such code surgery.
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.
Ok.
…th r-values Enables passing array r-values to val parameter.
…th r-values Enables passing array r-values to val parameter.
@nordlow this is currently failing the testing pipeline. |
Thanks. I'm gonna branch of minor changes from this. So I'm gonna wait with fixing this. |
This PR currently has two issue that blocks a complete reduction of code bloat in template-variadic formatting and printing functions like auto format(T...)(const(T) args) {} fails when any of the auto format(T...)(const T args) {} fails when any of the These two issues also holds for Afaict, both are related to lack of
I'm personally not sure which alternative is the best long-term. FYI, @adamdruppe @maxhaton. |
cd57a90
to
0eaeb78
Compare
@nordlow I don't know of any plans to introduce tail-constness into the language, so I suggest, in the interest of progress to implement in this PR whatever works and is not dependent on tail-constness. Otherwise, this will be stalled forever. |
PR closed as stalled. This can be resurrected for Phobos 3. |
This, for instance, reduces memory usage of unittest-checking
std.format.write
asdmd -o- -vcolumns -wi -debug -unittest -dip25 -dip1000 -version\=StdUnittest -I/home/per/Work/phobos/ /home/per/Work/phobos/std/format/write.d
from 386 MB to 356 MB.
all result in the same template instance of
format
.I've factored out integer printing to make the code not be instantiated for each integral type potentially reducing generated code a lot when formatting and printing integrals. Separate PR at Reduce template bloat in IntegralTypeOf-overload of formatValueImpl #8278.
The refactoring in
formatValue
avoids the need to instantiate the wrapper templatesBooleanTypeOf
,IntegralTypeOf
, etc.I'm gonna look into other types classes such as floating point types next.
Putting this out into the open to see what CIs feel about this.
Feel free to tell me how you want this split up.