r/cpp • • May 10 '20

Make LLVM fast again

https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html
150 Upvotes

88 comments sorted by

View all comments

Show parent comments

-2

u/griceylipper May 11 '20

Yes, but my point is this - when you consider the decisions made by the people designing C++, and the effort going compilers like Clang - both must be severely misguided before a very small team like Thekla can produce a very serious competition that is many orders of magnitude faster. Yes, C++ is more complicated, but only because it was designed that way. Jonathan Blow cares about the time developers waste waiting on compilation, trying to understand bad error messages, etc., and keeps the "joy of programming" as a very high priority. I honestly think C++ will start to fade away to be another language of the past like Fortran or COBOL once Jai is (eventually) released.

3

u/encyclopedist May 11 '20

Last time I tested, clang and GCC were able to compile about 200k lines per second (after preprocessing). There are no "many orders of magnitude".

Also, we are discussing LLVM here, which does not know much about the language we are compiling.

Also, as far as I know, Jai's backend has very rudimentary optimizations.

2

u/griceylipper May 11 '20

clang and GCC were able to compile about 200k lines per second (after preprocessing)

I'm skeptical regarding that figure - do you have any links you can point me to? I know this is really old, but here Jonathan Blow discusses progress of speed in his language at a time when it was not at its best. He specifically talks about 1m loc/sec at 25:21.

Also, as far as I know, Jai's backend has very rudimentary optimizations.

Jai has two backends - an LLVM one to take advantage of optimisations for release builds, and his own x64 backend for development. The x64 backend is more rudimentary, but that's sort of the point - it's designed for fast turnaround. Some limited optimisation has been spoken about for this, but it will never be as optimised as the LLVM backend, because that's not its purpose.

2

u/encyclopedist May 11 '20

I don't remember what code I tested that time, so I started now with a hello world code.

#include <iostream>
int main() {
    std::cout << "Hello" << std::endl;
}

Then I preprocessed it

g++ -E -std=c++17 hello_world.cpp > preprocessed.cpp

Preprocessed file is 773 kB in size, with 22k lines of code:

$ tokei preprocessed.cpp
------------------------------------------------------------------------------
 Language            Files        Lines         Code     Comments       Blanks
-------------------------------------------------------------------------------
 C++                     1        31761        22020            0         9741
-------------------------------------------------------------------------------
 Total                   1        31761        22020            0         9741
-------------------------------------------------------------------------------

Compilation of this file takes 0.3 s

Benchmark #1: g++ -c -std=c++17 -O3 preprocessed.cpp
  Time (mean ± σ):     305.1 ms ±   7.3 ms    [User: 281.8 ms, System: 23.4 ms]
  Range (min … max):   295.8 ms … 315.6 ms    10 runs

Which means GCC can compile 73 kloc/s. Lower than 200 kloc/s I mentioned before, but still not "many orders slower". Clang compiles the same code in ~270 ms.

I also tested on more realistic code. I took the file ninja.cc from Ninja build system. Preprocessed file is 1.7 MB in size and has 45.7 kloc. It takes 830 ms to compile, which gives ~ 55 kloc/s.