-
-
Notifications
You must be signed in to change notification settings - Fork 702
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
Decrease template bloat for string functions #6743
Conversation
1af386f
to
fd04b7d
Compare
Thanks for your pull request, @n8sh! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#6743" |
f60c1a1
to
a80f54f
Compare
87f692e
to
8033890
Compare
e1a4c91
to
f4b5c98
Compare
I assumed you grep'ed for the usage of decodeImpl to make sure CastForDecode is used when needed? |
In effect yes. The only places it's not used are in unittests. |
Wouldn't it be better if decodeImpl would call CastForDecode, because currently we have to make sure that people remember calling CastForDecode if necessary. |
Can you suggest a good way to do that? I'm not enthusiastic about adding a wrapper function. |
sorry, strike my last comment. I misread the call side. |
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.
Have you done anything to measure these changes? Given the size and complexity of decodeImpl
, it wouldn't surprise me at all if this does reduce template bloat, but you are actually adding template instantiations into the mix into order to avoid template instantiations, and the vast majority of string code is just string
. So, for some programs at least, this is probably adding template bloat, though overall, it probably is reducing it. It also has a number of scope
-related changes that seem orthogonal to the main point of the PR, which muddies things a bit.
Regardless, unless there's something that I'm missing here, I think that inout
should be completely removed from the PR. It's my understanding that it has no impact on how many templates are instantiated, and it really doesn't provide any benefit, because the code is templated. It just further complicates the code.
@jmdavis The purpose of this PR is not to improve compile times by reducing the absolute number of template uses, it's to improve the cache performance of the final executable by decreasing the number of distinct functions created by template instantiation. Look at the generated assembly for this code: https://run.dlang.io/is/fMHThw void foo(T)(ref T[] a)
{
a = a[1 .. $];
}
void bar(T)(ref inout(T)[] a)
{
a = a[1 .. $];
}
void main()
{
int[] a = [1, 2, 3];
const(int)[] b = [4, 5, 6];
immutable(int)[] c = [7, 8, 9];
foo(a);
foo(b);
foo(c);
bar(a);
bar(b);
bar(c);
} The generated code has 3 separate |
f4b5c98
to
f8bb34b
Compare
717e83d
to
f8bb34b
Compare
c9caece
to
0f20d87
Compare
Yep, that went green. |
Since |
Ooohh, or not. Why is style passing now? |
0f20d87
to
12d074c
Compare
And now |
12d074c
to
4e1bbb1
Compare
4e1bbb1
to
9ad96f0
Compare
a95d31f
to
77b15d9
Compare
Use const(E)[] instead of E[] when it is valid and doesn't change the return type.
77b15d9
to
4cc47e6
Compare
// if (/* same constraint */) | ||
// --- | ||
// as that would cause fewer distinct functions to be generated with | ||
// IFTI, but that caused a linker error in the test suite on Win32_64. |
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.
Its great that you found the source of the error, did you submit a bug for it?
The Win32_64 linker error that prevented this from being included in PR dlang#6743 no longer occurs in CI.
Use const(E)[] instead of E[] when it is valid and doesn't change the return type.