August 29, 2015
https://issues.dlang.org/show_bug.cgi?id=14975

          Issue ID: 14975
           Summary: DMD refuses to inline even trivial struct constructors
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: thomas.bockman@gmail.com

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;
    }
}

--