On Wednesday, 19 August 2015 at 22:15:46 UTC, tsbockman wrote:
I lack the assembly language skills to determine the cause(s) myself, but my [CheckedInt](https://github.com/tsbockman/CheckedInt) benchmark runs about 10x slower when compiled with DMD rather than GDC. I'm sure there's some low-hanging fruit in there somewhere...

While doing some refactoring and updating 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;
    }
}

Reply via email to