Bug 18511 – Using std.range / std.algorithm templates cause big slowdown in compilation time

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-02-23T20:05:29Z
Last change time
2024-12-13T18:57:21Z
Assigned to
No Owner
Creator
hsteoh
Moved to GitHub: dmd#19397 →

Comments

Comment #0 by hsteoh — 2018-02-23T20:05:29Z
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.
Comment #1 by hsteoh — 2018-02-23T20:06:42Z
Sorry, missed the command for compiling the slow version: time dmd -c -version=slow test.d
Comment #2 by robert.schadek — 2024-12-13T18:57:21Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19397 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB