Live data from Hacker News

Dart team posts an example of fast code with 22ms for a “Hello world”

twitter.com

21–30 of 33 posts

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#21

How it compares with go, node and java?

Here are a few comparisons (13" MBP, YMMV). $ ./hyperfine './hello.gonative' --warmup 10 Benchmark #1: ./hello.gonative Time (mean ± σ): 3.3 ms ± 0.9 ms [User: 1.2 ms, System: 1.2 ms] Range (min … max): 2.4 ms … 14.2 ms 455 runs $ ./hyperfine './hello.dartnative' --warmup 10 Benchmark #1: ./hello.dartnative Time (mean ± σ): 8.2 ms ± 0.4 ms [User: 3.9 ms, System: 3.6 ms] Range (min … max): 7.5 ms … 10.2 ms 243 runs $…

Which JDK? OpenJDK 14 on my machine:

    ~> Measure-Command { java Main }
    Milliseconds      : 59

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#22
post #21

Earlier quoted context omitted.

Here are a few comparisons (13" MBP, YMMV). $ ./hyperfine './hello.gonative' --warmup 10 Benchmark #1: ./hello.gonative Time (mean ± σ): 3.3 ms ± 0.9 ms [User: 1.2 ms, System: 1.2 ms] Range (min … max): 2.4 ms … 14.2 ms 455 runs $ ./hyperfine './hello.dartnative' --warmup 10 Benchmark #1: ./hello.dartnative Time (mean ± σ): 8.2 ms ± 0.4 ms [User: 3.9 ms, System: 3.6 ms] Range (min … max): 7.5 ms … 10.2 ms 243 runs $…

Which JDK? OpenJDK 14 on my machine: ~> Measure-Command { java Main } Milliseconds : 59

Also with GraalVM Native:

   ~> .\native-image.cmd --static Main Main
   ~> Measure-Command { ./Main }
   Milliseconds      : 16

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#23

Lots of bashing in this thread, but to clarify a bit: The Dart VM is roughly based on V8's internals. Running dart alone would be similar to running node, which needs to initialize the VM, parse the code, and run it. This is obviously slower than a pre-compiled binary. dart2native brings it half-way to native, by doing parsing and initialization, and saving a memory snapshot right before executing the main function.…

All that proves is that V8 is a beast, similar to the JVM. Here's what an alternative world could look like:

  $ time luajit -e 'print"hello world"'
  hello world

  real 0m0.002s
  user 0m0.000s
  sys  0m0.002s
But it's worse than that, because the time at issue is for the AOT-compiled native code binary.

To be fair, I presume that the included runtime is written in C++, and modern C++ coding styles are pretty inefficient. Lots of small, dynamic allocations. Too much of the wrong kinds of abstraction. It's what happens when you shoehorn problems into established solution models, rather than approach development, including boiler plate code, as crafting a bespoke solution model fit to the problem. But the latter makes onboarding new engineers more difficult--you can't start hacking without first grasping the larger architecture--and therefore frowned upon in larger companies, or in small companies that equivocate big company approaches to "best practice".

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#24

Earlier quoted context omitted.

Probably want -Os (and strip afterwards) if you're interested in startup time. C is also 1ms. C++ has a big cxxrt that zig doesn't. FWIW c++ only takes 2ms on my (quite slow) machine.

would ios_base::sync_with_stdio(false); also help?

In my benchmark, the c++ version uses the c api (printf rather than cout), so it wouldn't make a difference.

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#25
post #23

Lots of bashing in this thread, but to clarify a bit: The Dart VM is roughly based on V8's internals. Running dart alone would be similar to running node, which needs to initialize the VM, parse the code, and run it. This is obviously slower than a pre-compiled binary. dart2native brings it half-way to native, by doing parsing and initialization, and saving a memory snapshot right before executing the main function.…

All that proves is that V8 is a beast, similar to the JVM. Here's what an alternative world could look like: $ time luajit -e 'print"hello world"' hello world real 0m0.002s user 0m0.000s sys 0m0.002s But it's worse than that, because the time at issue is for the AOT-compiled native code binary. To be fair, I presume that the included runtime is written in C++, and modern C++ coding styles are pretty inefficient. Lots…

Poking around on my laptop, dash and perl take about 2ms. Python takes 12.

Anyway, the modern c++ I use avoids allocations like the plague.

I subscribe to the idea that C++ is a language for standard library implementors, and that std:: is mostly placeholders for the “real” implementation you’ll use later.

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#26

Earlier quoted context omitted.

That's an odd contrast (one frame of a game versus loading a language runtime). How long does a game engine take to load? A reasonable comparison is whether Dart is able to render complex experiences at 60fps (i.e. 16ms / frame) on a low-end phone device, which is the primary use case.

Depends on the game engine. Jonathan Blow has written one for his upcoming Sokoban game and it completely compiles and launches the game from source in about a second and a half. No incremental compilation, no debug mode. That's not just the runtime engine, it's the tooling to make the game, as well. A second and a half, from source files on disk to a running binary showing a 3D viewport on screen. Think about that.…

Studies have shown that user interface latency was at its all time best in the mid-80’s, assuming the user was using a dumb terminal that talked to a mainframe.

Modern software sucks.

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#27
post #5

It's a startup time of the runtime. More interested in results with two "hello,world"s. How much the next one going to cost. Also C++ with cout, -O3 is 4ms and one in *.Zig is 1ms for some reason.

Yup. Dart has a runtime. Runtimes have to spin up when they're run cold.

But we shouldn't let facts get in the way of a good Hackernews hivemind dogpile. Dart bad!

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#28

Earlier quoted context omitted.

As people pointed out in the thread, in 22ms a game will have rendered a full 3D world with physics and audio multiple times. 22ms is... not fast. Unless you count modern world where "fast" is "anything that runs under 10 seconds".

This is like saying a game runs at 0.1fps because it took a couple seconds to load at the start. This is initial load time. Printing likely account for <1% of the actual time, the rest being initializing the program

Other examples in the thread show people routinely outputting "Hello, world" from cold start in under 5ms.

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#29
post #19

[disclaimer: I work on the Dart team.] As others have already noted, the intent here is to purely measure the one-time startup cost of the runtime in ahead-of-time compiled code - i.e., the amount of time necessary before we can starting executing any user code - i.e., the print in this case. It's assumed that the time to do the actual print is trivial here. If you want to compare, you might compare with other garbag…

The text on the page is "AOT-compile apps to native machine code for instant startup".

And now you're saying that the start up is actually not instant.

- LuaJIT: 0.002ms [1]

- Dash and perl take about 2ms. Python takes 12. [2]

- Perl 0.008s [3]

- Python 0.009s [4]

And that's before we talk about compilation speeds [5]

[1] https://news.ycombinator.com/item?id=23109404

[2] https://news.ycombinator.com/item?id=23110092

[3] https://twitter.com/beeonbird/status/1258472898446180353

[4] https://twitter.com/f00zz_/status/1258427236891480067

[5] https://twitter.com/alexyanov/status/1258474918607544322

Re: Dart team posts an example of fast code with 22ms for a “Hello world”

#30
post #19

[disclaimer: I work on the Dart team.] As others have already noted, the intent here is to purely measure the one-time startup cost of the runtime in ahead-of-time compiled code - i.e., the amount of time necessary before we can starting executing any user code - i.e., the print in this case. It's assumed that the time to do the actual print is trivial here. If you want to compare, you might compare with other garbag…

The text on the page is "AOT-compile apps to native machine code for instant startup". And now you're saying that the start up is actually not instant. - LuaJIT: 0.002ms [1] - Dash and perl take about 2ms. Python takes 12. [2] - Perl 0.008s [3] - Python 0.009s [4] And that's before we talk about compilation speeds [5] [1] https://news.ycombinator.com/item?id=23109404 [2] https://news.ycombinator.com/item?id=23110092…

"Instant" is a relative word (unless we're actually at 0 time :-)).

We're focus on client apps, where we're really focused on human perception. In that sense, I'd consider 22ms or 2ms as instant (for startup). I wouldn't consider 2s as instant.

I'm not saying Dart doesn't have room to get better, but there are diminishing returns at a certain point.

Post reply on HN