August 26, 2020
On Wednesday, 26 August 2020 at 09:19:47 UTC, Atila Neves wrote:
> On Thursday, 20 August 2020 at 23:16:40 UTC, Stefan Koch wrote:
>> On Thursday, 20 August 2020 at 22:20:19 UTC, Andrei Alexandrescu wrote:
>>> On 8/20/20 4:50 PM, Per Nordlöw wrote:
>>>> After having evaluated the compilation speed of D compared to other languages at
>>>> 
>>>>      https://github.com/nordlow/compiler-benchmark
>>>> 
>>>> I wonder; is there any language that compiles to native code anywhere nearly as fast or faster than D, except C?
>>>> 
>>>> If so it most likely needs to use a backend other than LLVM.
>>>> 
>>>> I believe Jai is supposed to do that but it hasn't been released yet.
>>>
>>> I tried Python a while ago, the build-run cycle for a simple program was about the same. For Perl it was faster.
>>
>> Neither perl nor python compile their code by default.
>
> Yes, they do. Just not to x86.

If they compile to bytecode that's still not native code.
Which is what was asked if I understood the question correctly.

August 26, 2020
On Wednesday, 26 August 2020 at 11:49:06 UTC, Jacob Carlborg wrote:
> [snip]
>
> BTW, I see that you download DMD from dlang.org. The binaries at dlang.org are compiled with DMD itself. You should compile DMD yourself using LDC, with the appropriate flags. It will give you a boost, perhaps 30%.
>
> [1] https://crystal-lang.org
>
> --
> /Jacob Carlborg

After [1] I was under the assumption that the linux versions were already compiled on LDC first. Is it only the Windows release that is compiled with LDC?

[1] https://dlang.org/changelog/2.091.0.html#windows
August 26, 2020
On 8/25/20 9:13 PM, James Lu wrote:
> V8 JavaScript compiles faster:
> 
> $ d8 --always-opt --trace-opt --single-threaded --no-compilation-cache mandelbrot.js | ts -s "%.s"

Interesting. What is the result of that compilation? A traditional binary file, or a webassembly?
August 26, 2020
On 8/25/20 9:13 PM, James Lu wrote:
> On Thursday, 20 August 2020 at 20:50:25 UTC, Per Nordlöw wrote:
>> After having evaluated the compilation speed of D compared to other languages at
>>
>>     https://github.com/nordlow/compiler-benchmark
>>
>> I wonder; is there any language that compiles to native code anywhere nearly as fast or faster than D, except C?
>>
>> If so it most likely needs to use a backend other than LLVM.
>>
>> I believe Jai is supposed to do that but it hasn't been released yet.
> 
> V8 JavaScript compiles faster:
> 
> $ d8 --always-opt --trace-opt --single-threaded --no-compilation-cache mandelbrot.js | ts -s "%.s"
> 0.000025 [compiling method 0x3fc50821068d <JSFunction (sfi = 0x3fc508210165)> using TurboFan]
> 0.001651 [optimizing 0x3fc50821068d <JSFunction (sfi = 0x3fc508210165)> - took 4.455, 41.945, 0.052 ms]
> 0.001707 [optimizing 0x3fc508085b65 <JSFunction Complex (sfi = 0x3fc508210261)> because --always-opt]
> 0.001736 [compiling method 0x3fc508085b65 <JSFunction Complex (sfi = 0x3fc508210261)> using TurboFan]
> 0.001763 [optimizing 0x3fc508085b65 <JSFunction Complex (sfi = 0x3fc508210261)> - took 0.125, 0.284, 0.019 ms]
> 0.001789 [optimizing 0x3fc508211665 <JSFunction iterate_mandelbrot (sfi = 0x3fc508210229)> because --always-opt]
> 0.001817 [compiling method 0x3fc508211665 <JSFunction iterate_mandelbrot (sfi = 0x3fc508210229)> using TurboFan]
> 0.001842 [optimizing 0x3fc508211665 <JSFunction iterate_mandelbrot (sfi = 0x3fc508210229)> - took 0.167, 1.197, 0.022 ms]
> 0.001868 [optimizing 0x3fc508085b85 <JSFunction abs (sfi = 0x3fc508210299)> because --always-opt]
> 0.001892 [compiling method 0x3fc508085b85 <JSFunction abs (sfi = 0x3fc508210299)> using TurboFan]
> 0.001916 [optimizing 0x3fc508085b85 <JSFunction abs (sfi = 0x3fc508210299)> - took 0.125, 0.421, 0.025 ms]
> 0.002093 [optimizing 0x3fc508085bbd <JSFunction mul (sfi = 0x3fc508210309)> because --always-opt]
> 0.002337 [compiling method 0x3fc508085bbd <JSFunction mul (sfi = 0x3fc508210309)> using TurboFan]
> 0.002365 [optimizing 0x3fc508085bbd <JSFunction mul (sfi = 0x3fc508210309)> - took 0.134, 0.550, 0.023 ms]
> 0.002389 [optimizing 0x3fc508085ba1 <JSFunction add (sfi = 0x3fc5082102d1)> because --always-opt]
> 0.002498 [compiling method 0x3fc508085ba1 <JSFunction add (sfi = 0x3fc5082102d1)> using TurboFan]

I just want to point out that ts is not an accurate timestamping system. The shell is starting ts and d8 simultaneously, and it's very possible that d8 has done a lot of stuff by the time ts gets around to deciding what timestamp 0 is. In fact, d8 could be completely finished, and all its output buffered in the pipe, before ts does anything. Especially when these times are so short.

Not saying the data is wrong, but I am not certain this is proof.

Use shell time builtin.

-Steve
August 26, 2020
On Wednesday, 26 August 2020 at 13:16:08 UTC, Andrei Alexandrescu wrote:
> On 8/25/20 9:13 PM, James Lu wrote:
>> V8 JavaScript compiles faster:
>> 
>> $ d8 --always-opt --trace-opt --single-threaded --no-compilation-cache mandelbrot.js | ts -s "%.s"
>
> Interesting. What is the result of that compilation? A traditional binary file, or a webassembly?

It results in machine code (in my case, x86) in memory.
August 26, 2020
On Wednesday, 26 August 2020 at 14:45:48 UTC, Steven Schveighoffer wrote:
> On 8/25/20 9:13 PM, James Lu wrote:
>> V8 JavaScript compiles faster:
>> 
>> $ d8 --always-opt --trace-opt --single-threaded
>
> I just want to point out that ts is not an accurate timestamping system. The shell is starting ts and d8 simultaneously, and it's very possible that d8 has done a lot of stuff by the time ts gets around to deciding what timestamp 0 is. In fact, d8 could be completely finished, and all its output buffered in the pipe, before ts does anything. Especially when these times are so short.
>
> Not saying the data is wrong, but I am not certain this is proof.
>
> Use shell time builtin.
>
> -Steve

$ time d8 --always-opt --trace-opt --single-threaded --no-compilation-cache mandelbrot.js
[compiling method 0x182b08210471 <JSFunction (sfi = 0x182b08210129)> using TurboFan]
[optimizing 0x182b08210471 <JSFunction (sfi = 0x182b08210129)> - took 0.888, 1.326, 0.026 ms]
[optimizing 0x182b0821073d <JSFunction main (sfi = 0x182b082101e5)> because --always-opt]
[compiling method 0x182b0821073d <JSFunction main (sfi = 0x182b082101e5)> using TurboFan]
[optimizing 0x182b0821073d <JSFunction main (sfi = 0x182b082101e5)> - took 0.401, 3.229, 0.044 ms]
[optimizing 0x182b08085bdd <JSFunction Complex (sfi = 0x182b0821021d)> because --always-opt]
[compiling method 0x182b08085bdd <JSFunction Complex (sfi = 0x182b0821021d)> using TurboFan]
[optimizing 0x182b08085bdd <JSFunction Complex (sfi = 0x182b0821021d)> - took 0.138, 0.296, 0.028 ms]
[optimizing 0x182b08210709 <JSFunction iterate_mandelbrot (sfi = 0x182b082101ad)> because --always-opt]
[compiling method 0x182b08210709 <JSFunction iterate_mandelbrot (sfi = 0x182b082101ad)> using TurboFan]
[optimizing 0x182b08210709 <JSFunction iterate_mandelbrot (sfi = 0x182b082101ad)> - took 0.228, 1.619, 0.035 ms]
[optimizing 0x182b08085bfd <JSFunction abs (sfi = 0x182b08210255)> because --always-opt]
[compiling method 0x182b08085bfd <JSFunction abs (sfi = 0x182b08210255)> using TurboFan]
[optimizing 0x182b08085bfd <JSFunction abs (sfi = 0x182b08210255)> - took 0.213, 0.502, 0.033 ms]
[optimizing 0x182b08085c35 <JSFunction mul (sfi = 0x182b082102c5)> because --always-opt]
[compiling method 0x182b08085c35 <JSFunction mul (sfi = 0x182b082102c5)> using TurboFan]
[optimizing 0x182b08085c35 <JSFunction mul (sfi = 0x182b082102c5)> - took 0.183, 0.643, 0.030 ms]
[optimizing 0x182b08085c19 <JSFunction add (sfi = 0x182b0821028d)> because --always-opt]
[compiling method 0x182b08085c19 <JSFunction add (sfi = 0x182b0821028d)> using TurboFan]
[optimizing 0x182b08085c19 <JSFunction add (sfi = 0x182b0821028d)> - took 0.150, 0.449, 0.041 ms]

real	0m0.052s
user	0m0.022s
sys	0m0.021s

--always-opt makes V8 compile the function the first time it is called, so we can ignore interpreter overhead. I changed the code to quit after one function call, so we would measure how long it takes to compile and run the compilation.

For the sake of transparency, I modified some of the code to move it into a main function to ensure it would compile the code. Surprisingly, doing this reduced compilation time.

Here is the exact code I used: https://gist.github.com/CrazyPython/3552e1405dbb4b640810f6443cd0a015
August 26, 2020
On Wednesday, 26 August 2020 at 13:16:08 UTC, Andrei Alexandrescu wrote:
> On 8/25/20 9:13 PM, James Lu wrote:
>> V8 JavaScript compiles faster:
>> 
>> $ d8 --always-opt --trace-opt --single-threaded --no-compilation-cache mandelbrot.js | ts -s "%.s"
>
> Interesting. What is the result of that compilation? A traditional binary file, or a webassembly?

In an earlier post from me in this thread, I added together V8's internal timing to suggest that its codgen (SSA building, SSA optimization, conversion to machine code) phase runs 100 times faster than LLVM on similar code in D.
August 26, 2020
On Thursday, 20 August 2020 at 20:50:25 UTC, Per Nordlöw wrote:
> I wonder; is there any language that compiles to native code anywhere nearly as fast or faster than D, except C?

Hi, you may want to try benchmarking my compiler of Vox language:
https://github.com/MrSmith33/tiny_jit
I designed it with high compilation speed in mind.

I added statically compiled linux build to CI tag.
Or compile manually with:
source> ~/dlang/ldc-1.22.0/bin/ldc2 -d-version=cli -m64 -O3 -release -boundscheck=off -enable-inlining -flto=full -i main.d -of=./tjc

So far it may only produce executables for win64, but it should be enough for you purpose.
August 26, 2020
On 8/26/20 12:00 PM, James Lu wrote:
> On Wednesday, 26 August 2020 at 14:45:48 UTC, Steven Schveighoffer wrote:
>> On 8/25/20 9:13 PM, James Lu wrote:
>>> V8 JavaScript compiles faster:
>>>
>>> $ d8 --always-opt --trace-opt --single-threaded
>>
>> I just want to point out that ts is not an accurate timestamping system. The shell is starting ts and d8 simultaneously, and it's very possible that d8 has done a lot of stuff by the time ts gets around to deciding what timestamp 0 is. In fact, d8 could be completely finished, and all its output buffered in the pipe, before ts does anything. Especially when these times are so short.
>>
>> Not saying the data is wrong, but I am not certain this is proof.
>>
>> Use shell time builtin.
> 
> $ time d8 --always-opt --trace-opt --single-threaded --no-compilation-cache mandelbrot.js
> [compiling method 0x182b08210471 <JSFunction (sfi = 0x182b08210129)> using TurboFan]
> [optimizing 0x182b08210471 <JSFunction (sfi = 0x182b08210129)> - took 0.888, 1.326, 0.026 ms]
> [optimizing 0x182b0821073d <JSFunction main (sfi = 0x182b082101e5)> because --always-opt]
> [compiling method 0x182b0821073d <JSFunction main (sfi = 0x182b082101e5)> using TurboFan]
> [optimizing 0x182b0821073d <JSFunction main (sfi = 0x182b082101e5)> - took 0.401, 3.229, 0.044 ms]
> [optimizing 0x182b08085bdd <JSFunction Complex (sfi = 0x182b0821021d)> because --always-opt]
> [compiling method 0x182b08085bdd <JSFunction Complex (sfi = 0x182b0821021d)> using TurboFan]
> [optimizing 0x182b08085bdd <JSFunction Complex (sfi = 0x182b0821021d)> - took 0.138, 0.296, 0.028 ms]
> [optimizing 0x182b08210709 <JSFunction iterate_mandelbrot (sfi = 0x182b082101ad)> because --always-opt]
> [compiling method 0x182b08210709 <JSFunction iterate_mandelbrot (sfi = 0x182b082101ad)> using TurboFan]
> [optimizing 0x182b08210709 <JSFunction iterate_mandelbrot (sfi = 0x182b082101ad)> - took 0.228, 1.619, 0.035 ms]
> [optimizing 0x182b08085bfd <JSFunction abs (sfi = 0x182b08210255)> because --always-opt]
> [compiling method 0x182b08085bfd <JSFunction abs (sfi = 0x182b08210255)> using TurboFan]
> [optimizing 0x182b08085bfd <JSFunction abs (sfi = 0x182b08210255)> - took 0.213, 0.502, 0.033 ms]
> [optimizing 0x182b08085c35 <JSFunction mul (sfi = 0x182b082102c5)> because --always-opt]
> [compiling method 0x182b08085c35 <JSFunction mul (sfi = 0x182b082102c5)> using TurboFan]
> [optimizing 0x182b08085c35 <JSFunction mul (sfi = 0x182b082102c5)> - took 0.183, 0.643, 0.030 ms]
> [optimizing 0x182b08085c19 <JSFunction add (sfi = 0x182b0821028d)> because --always-opt]
> [compiling method 0x182b08085c19 <JSFunction add (sfi = 0x182b0821028d)> using TurboFan]
> [optimizing 0x182b08085c19 <JSFunction add (sfi = 0x182b0821028d)> - took 0.150, 0.449, 0.041 ms]
> 
> real    0m0.052s
> user    0m0.022s
> sys    0m0.021s
> 
> --always-opt makes V8 compile the function the first time it is called, so we can ignore interpreter overhead. I changed the code to quit after one function call, so we would measure how long it takes to compile and run the compilation.
> 
> For the sake of transparency, I modified some of the code to move it into a main function to ensure it would compile the code. Surprisingly, doing this reduced compilation time.
> 
> Here is the exact code I used: https://gist.github.com/CrazyPython/3552e1405dbb4b640810f6443cd0a015

Thanks, that's really impressive. D has some significant overhead which might explain some of the discrepancy.

Compiling an empty main function with dmd takes 0.128 seconds on my system, but of course comparing my system to yours isn't going to be useful.

Compiling with -betterC an empty main takes 0.065 seconds, which means about half the overhead is spent compiling D runtime setup things?

It is difficult to assign what is overhead and what is compilation, especially for a JIT compiler, so the claim of "100x", may not be accurate, especially with these low timings. Still, it definitely seems faster than D.

-Steve
August 26, 2020
On Wednesday, 26 August 2020 at 16:08:15 UTC, MrSmith wrote:
> Hi, you may want to try benchmarking my compiler of Vox language:
> https://github.com/MrSmith33/tiny_jit
> I designed it with high compilation speed in mind.

Looks really interesting! Thanks. I'll try it out soon.