When the arrays given to std.numeric.dotProduct are very small, its performance compared to an inlined foreach loop becomes quite bad (a simple benchmarks on request). This is a hard problem to solve in general (you probably need profile-driven optimizations, that maybe future LLVM versions will perform with -O5 or -O6 level optimization or more), but there is an important special case where I think there is a way to improve the situation: int[3] a, b; auto r = dotProduct(a, b); In this situation dotProduct may just recognize (with template constraints) that both a and b are fixed-sized arrays, that their length is the same (so no need to test it again at runtime), and that this length is small (less than 6? 8?). In this case a function template overload for dotProduct performs a "static foreach" on the items of a and b (in theory you are also allowed to use inline asm with few instructions that use SIMD registers, but currently with DMD this kills inlining, so it's not good enough). I think in this case DMD will *inline* this very simple dotProduct function overload, allowing good enough performance. This low performance problem has caused problems in my code. See also bug 4393
@n8sh created dlang/phobos pull request #6990 "Fix Issue 6657 - dotProduct overload for small fixed size arrays" fixing this issue: - Fix Issue 6657 - dotProduct overload for small fixed size arrays https://github.com/dlang/phobos/pull/6990
dlang/phobos pull request #6990 "Fix Issue 6657 - dotProduct overload for small fixed size arrays" was merged into master: - c334d376011a04356dc150f765a54e7ad1c05810 by Nathan Sashihara: Fix Issue 6657 - dotProduct overload for small fixed size arrays https://github.com/dlang/phobos/pull/6990