[Issue 18511] New: Using std.range / std.algorithm templates cause big slowdown in compilation time
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Feb 23 20:05:29 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18511
Issue ID: 18511
Summary: Using std.range / std.algorithm templates cause big
slowdown in compilation time
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: hsteoh at quickfur.ath.cx
Code:
------
double dot(double[] a, double[] b) {
version(fast) {
assert(a.length == b.length);
double acc = 0.0;
foreach (i; 0 .. a.length)
acc += a[i] * b[i];
return acc;
}
version (slow) {
import std.range : zip;
import std.algorithm.iteration : fold, map;
return zip(a[], b[])
.map!(x => x[0]*x[1])
.fold!((a, b) => a + b)(0.0);
}
}
------
Compiling with manually-written loop:
------
$ time dmd -c -version=fast test.d
real 0m0.021s
user 0m0.014s
sys 0m0.007s
------
Compiling with fancy std.algorithm / std.range templates:
------
real 0m0.499s
user 0m0.444s
sys 0m0.054s
------
Now, I understand that using fancy generic code templates requires more work on
the part of the compiler, so some degree of slowdown in compilation times is to
be expected.
However, this is an *order of magnitude* slowdown in compiling two
functionally-equivalent pieces of code, and very simple code at that. Given
our current fast-fast-fast slogan, I think this is unacceptable.
--
More information about the Digitalmars-d-bugs
mailing list