Live data from Hacker News

4x Smaller, 50x Faster

blog.asciinema.org

201–205 of 205 posts

Re: 4x Smaller, 50x Faster

#201

Earlier quoted context omitted.

Listen, Clojure isn't born yesterday, it's around for quite some time and it's a mature product. And when you have mature products that are still in development and people behind it do evolve it then you also get all kind of optimizations. I would expect the system maybe to be slower like 20 to maximum 50% (as in Rust to be maximum 2 times faster) but 50 times faster?. That's already brain in the chair mistake.

If we were talking about Clojure, I would agree that 50x would indicate that something is off. But since we're talking ClojureSCRIPT, it doesn't surprise me. Although, fair enough, it's a rewrite, and the author has the benefit of experience with the first implementation when writing this one. A second implementation in ClojureScript would likely have been faster than the first one. But 50x faster? Unlikely. > Is Web…

> But 50x faster? Unlikely.

And yet it is.

The biggest factor here is that CLJS is interpreted, GC-ed with immutable data structures while Rust is lower level with highly optimized WASM bytecode, that's optimized by Rust/LLVM compiler ahead of time.

So, when there's a lot of terminal activity (high speed colorful animation), the terminal emulator in CLJS implementation allocates and GCs millions of data structures every second. In Rust implementation there's very little allocation because most code operates on already pre-allocated buffers, and just mutates then. Both approaches are standard to their language. I could have tried all sorts of tricks (in fact I tried some) in CLJS to make this implementation faster but it would very quickly make the code non-idiomatic, and not fun to work with. But let's say I could make the CLJS impl be on par with a theoretical plain JS impl - this would likely still be many times slower than a basic Rust impl. Modern JS engines are amazing but they just can't beat WASM. Maybe some day :)

Re: 4x Smaller, 50x Faster

#202
post #197

Earlier quoted context omitted.

"Any optimization you could do in Rust is probably easier in C++" I think this feeling comes from the fact that it takes longer to learn the basics of Rust compared to C++. However, once one has learned C++ or Rust to a reasonable level, I would argue that Rust is actually easier to use. This is not the same thing but many people make this claim.

> it takes longer to learn the basics of Rust compared to C++. Does it really? For example I'd think that initialization of objects is a topic that should be in "basics", yet initialization of objects in C++ seems disproportionately complex compared to Rust (at least to me).

Yet, object initialization is not a thing anyone needs to pay much attention to. Yes, there are historical rabbit holes, but you need not go down them.

Re: 4x Smaller, 50x Faster

#203
post #202
post #197

Earlier quoted context omitted.

> it takes longer to learn the basics of Rust compared to C++. Does it really? For example I'd think that initialization of objects is a topic that should be in "basics", yet initialization of objects in C++ seems disproportionately complex compared to Rust (at least to me).

Yet, object initialization is not a thing anyone needs to pay much attention to. Yes, there are historical rabbit holes, but you need not go down them.

> object initialization is not a thing anyone needs to pay much attention to

So it's perfectly fine for me to leave objects uninitialized because of lack of attention?

Re: 4x Smaller, 50x Faster

#204

Earlier quoted context omitted.

If we were talking about Clojure, I would agree that 50x would indicate that something is off. But since we're talking ClojureSCRIPT, it doesn't surprise me. Although, fair enough, it's a rewrite, and the author has the benefit of experience with the first implementation when writing this one. A second implementation in ClojureScript would likely have been faster than the first one. But 50x faster? Unlikely. > Is Web…

> But 50x faster? Unlikely. And yet it is. The biggest factor here is that CLJS is interpreted, GC-ed with immutable data structures while Rust is lower level with highly optimized WASM bytecode, that's optimized by Rust/LLVM compiler ahead of time. So, when there's a lot of terminal activity (high speed colorful animation), the terminal emulator in CLJS implementation allocates and GCs millions of data structures ev…

Read my comment again, I'm not saying what you think I'm saying.

Re: 4x Smaller, 50x Faster

#205
post #203
post #202

Earlier quoted context omitted.

Yet, object initialization is not a thing anyone needs to pay much attention to. Yes, there are historical rabbit holes, but you need not go down them.

> object initialization is not a thing anyone needs to pay much attention to So it's perfectly fine for me to leave objects uninitialized because of lack of attention?

It's perfectly fine to initialize them in the simplest and most obvious way.
Post reply on HN