Comment #0 by thomas.bockman — 2015-08-29T00:11:38Z
While doing some refactoring and updating [CheckedInt](https://github.com/tsbockman/CheckedInt) for DMD 2.068, I have discovered one major source of slowness: DMD cannot inline even trivial struct constructors:
// Error: constructor foo.this cannot inline function
struct foo {
int bar;
pragma(inline, true) this(int bar) {
this.bar = bar;
}
}
Refactoring my code to reduce the use of struct constructors yielded a 2x speed boost. The workaround is stupidly simple, though ugly:
struct foo {
int bar;
pragma(inline, true) static auto inline_cons(int bar) {
foo ret = void;
ret.bar = bar;
return ret;
}
}
Comment #1 by thomas.bockman — 2015-08-29T00:21:15Z
I have confirmed this issue affects 32-bit x86 Linux, as well.
Comment #2 by bugzilla — 2015-08-29T01:41:55Z
A more complete example would be appreciated. Sometimes, it is something else causing the problem.
Comment #3 by thomas.bockman — 2015-08-29T03:48:35Z
(In reply to Walter Bright from comment #2)
> A more complete example would be appreciated. Sometimes, it is something
> else causing the problem.
More complete in what sense?
From my experimentation, this code will fail to compile with DMD in release mode regardless of the context, but I can slap a main() function on it and make it a complete program, if you want:
module testd2;
import std.stdio;
struct foo {
int bar;
// Error: constructor testd2.foo.this cannot inline function
pragma(inline, true) this(int bar) {
this.bar = bar;
}
}
void main(string[] args) {
foo baz = 1;
writeln(baz.bar);
}
Comment #6 by thomas.bockman — 2015-09-05T07:49:06Z
I have tested, and PR #5033 does indeed fix this issue for me both in my simple test case, and also in the CheckedInt code where I originally discovered it. Thanks.