Zig: comptime parameters increases compile time by 6x

Created on 2 Jan 2020  Â·  3Comments  Â·  Source: ziglang/zig

https://github.com/schmee/zig-crypto/commit/b7fdfc736bbb9b50d0fb749d9a362773f0a21cee increases the compile time in zig-crypto in --release-fast (without zig-cache) from ~15 seconds to ~100 seconds. Must be hitting some pathological case in the compiler?

master (a52d62cba38d350a74e2d7246ec4e8c65ede740f):

➜  zig-crypto git:(master) ✗ time zig test test/des_test.zig --main-pkg-path ../ --release-fast
All 7 tests passed.
zig test test/des_test.zig --main-pkg-path ../ --release-fast  100.56s user 1.00s system 99% cpu 1:42.26 total

Commit before https://github.com/schmee/zig-crypto/commit/b7fdfc736bbb9b50d0fb749d9a362773f0a21cee:

➜  zig-crypto git:(d4f6a8c) ✗ time zig test test/des_test.zig --main-pkg-path ../ --release-fast
All 7 tests passed.
zig test test/des_test.zig --main-pkg-path ../ --release-fast  15.19s user 0.27s system 99% cpu 15.562 total

Versions:

➜  zig-crypto git:(master) ✗ zig version
0.5.0+576320e6d

macOS Mojave 10.14.6

optimization

Most helpful comment

Is there a writeup how comptime works? Is it a byte-code interpreter, or some variation of "actually compile this code (+ dependencies) and run it, dropping the results in-place"?

All 3 comments

It is expected that release builds take up to one order-of-magnitude longer than debug builds. The thing I am concerned about is that your debug build takes 15 seconds. The goal is to get that down to less than one second.

I understand that --release-fast will take longer in general, but a 6x increase from that commit alone seems a bit excessive, no? Also, debug build time is a bit inflated since running the tests takes around 5 seconds there.

When I remove these giant blocks of tests https://github.com/schmee/zig-crypto/blob/master/test/des_test.zig#L31-L1579 the compile time goes down to 4.7 seconds for release-fast and virtually nothing for debug, so those are definitely the cause of the slowdown.

Is there a writeup how comptime works? Is it a byte-code interpreter, or some variation of "actually compile this code (+ dependencies) and run it, dropping the results in-place"?

Was this page helpful?
0 / 5 - 0 ratings