Template wizardry and its cost
Adam D Ruppe
destructionator at gmail.com
Mon Jun 20 14:08:30 UTC 2022
On Monday, 20 June 2022 at 13:52:12 UTC, Bastiaan Veelo wrote:
> In total, we currently have 18997 individual translated
> strings. These are spread over 45 executables (unevenly).
That's nothing. Consider this test:
static foreach(i; 0 .. 20000)
mixin("string a", i, " = gettext!(i.stringof);");
void main() {}
$ /usr/bin/time dmd templatespam.d
0.32user 0.07system 0:00.40elapsed 98%CPU (0avgtext+0avgdata
135648maxresident)k
0inputs+1640outputs (0major+40899minor)pagefaults 0swaps
About 3x the memory and such of a basic hello world but as you
can see, 0.3s and 135 MB ram is nothing to worry about.
What about 200,000 strings?
$ /usr/bin/time dmd templatespam.d
Command terminated by signal 11
1.93user 0.40system 0:02.33elapsed 99%CPU (0avgtext+0avgdata
1415580maxresident)k
0inputs+0outputs (0major+353926minor)pagefaults 0swaps
Now it is adding up, 2s and 1.4 GB build time/ram. Which is still
inside the realm of acceptable cost, and it seems unlikely that
you'd ever have 200,000 user visible strings in a single build
unit anyway, well more than 10x what you have in your actual
application right now.
Please note that adding -version=extractStrings has no
significant impact on these numbers.
And this is with zero effort to optimize it.
More information about the Digitalmars-d
mailing list