News for hackers. Stuff that matters.
Re:Rustgo: Calling Rust from Go with near-zero overhead by artursapek on Tuesday August 15, 2017 @11:42AM (#15019243)
Is rust actually faster than go? I had no idea.
Re:Rustgo: Calling Rust from Go with near-zero overhead by random023987 on Tuesday August 15, 2017 @12:04PM (#15019432)
Rust has an explicit goal of zero-cost abstractions, while Go will allow more expensive abstractions in the service of simplicity.
Re:Rustgo: Calling Rust from Go with near-zero overhead by kmicklas on Tuesday August 15, 2017 @02:44PM (#15021098)
Go makes you write complex code so that they can be lazy and have a simple compiler.
Re:Rustgo: Calling Rust from Go with near-zero overhead by chc on Tuesday August 15, 2017 @03:05PM (#15021305)
Whereas Rust makes you write complex code because they put a lot of work into making a sophisticated compiler. It's a strange case of convergent evolution.
Re:Rustgo: Calling Rust from Go with near-zero overhead by Ar-Curunir on Tuesday August 15, 2017 @07:10PM (#15023579)
Rust code I've written has been fairly straightforward, so not sure why you think Rust is complex.
Re:Rustgo: Calling Rust from Go with near-zero overhead by kmicklas on Tuesday August 15, 2017 @05:18PM (#15022707)
More complex code that then actually does the thing you intend it to do rather than having subtle concurrency bugs (among other sorts).
Re:Rustgo: Calling Rust from Go with near-zero overhead by ori_b on Tuesday August 15, 2017 @12:11PM (#15019500)
For the kind of numerical code here, it's not going to be significantly faster.
Re:Rustgo: Calling Rust from Go with near-zero overhead by bascule on Tuesday August 15, 2017 @01:23PM (#15020278)
curve25519-dalek is 3X faster than the equivalent Go code (i.e. in the stdlib, authored by agl).

This is for a few reasons:

Rust has support for 128-bit integers (i.e. u128) which allows for faster arithmetic when operating on what are effectively multi-u128 bignums in an elliptic curve library.

LLVM is generally more sophisticated about optimizations. It wasn't until recently that go had an SSA-based compiler, so its optimizer isn't nearly as sophisticated as LLVM's, which has been developed for many years now.

Re:Rustgo: Calling Rust from Go with near-zero overhead by pjmlp on Tuesday August 15, 2017 @03:28PM (#15021511)
There is also gccgo, taking advantage of GCC's backend.

There is some ongoing work into an LLVM based compiler for Go, and LLVM now has Go as official supported bindings.

Re:Rustgo: Calling Rust from Go with near-zero overhead by tptacek on Wednesday August 16, 2017 @10:17AM (#15027622)
Go can and should fix the integer problem here. George Tankersley had a whole talk at Crypto Village this year about what a nightmare it is to write competitively fast curve code in Go.
Re:Rustgo: Calling Rust from Go with near-zero overhead by fnord123 on Tuesday August 15, 2017 @01:32PM (#15020367)
My information may be out of date, but last time I poked through the Go compiler, it did no vectorization or anything equivalent to march=native. So there's plenty of opportunity for Rust to be faster.
Re:Rustgo: Calling Rust from Go with near-zero overhead by digikata on Tuesday August 15, 2017 @03:45PM (#15021647)
As always, general benchmarks only give you limited insights, but this might be interesting:

Rust vs Go http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

Rust vs C http://benchmarksgame.alioth.debian.org/u64q/rust.html

Re:Rustgo: Calling Rust from Go with near-zero overhead by b4ux1t3 on Tuesday August 15, 2017 @11:48AM (#15019299)
You can tweak Go to make it as fast or faster, but, out of the box, the runtime is a bit slower.

Building is faster, though, so that's nice.

Re:Rustgo: Calling Rust from Go with near-zero overhead by ice109 on Tuesday August 15, 2017 @12:41PM (#15019803)
what are the things that you can tweak?
Re:Rustgo: Calling Rust from Go with near-zero overhead by nemo1618 on Tuesday August 15, 2017 @01:50PM (#15020555)
Most Go programs can benefit a lot from smarter memory management, which puts less strain on the GC and allows for certain optimizations. Things like refactoring your function to write into a pre-allocated buffer instead of returning a newly-allocated object. Or using a concrete type like `*os.File` instead of `io.Writer` so that the compiler can eliminate a heap allocation.

You can also eliminate some slice bounds-checking by "asserting" the size of the slice outside the hot path; see http://www.tapirgames.com/blog/go-1.7-bce

Go also has a great profiler for discovering exactly which functions/statements are causing slowdown or allocating excessive memory.

At the end of the day, though, I don't think most Go programs can be optimized to run as fast as their Rust equivalents (without dropping into asm, at least). There's just too much overhead that you aren't allowed to disable.

Re:Rustgo: Calling Rust from Go with near-zero overhead by b4ux1t3 on Tuesday August 15, 2017 @04:50PM (#15022367)
> At the end of the day, though, I don't think most Go programs can be optimized to run as fast as their Rust equivalents (without dropping into asm, at least)

To be clear, I meant programs that don't rely on things like concurrency or networking. For example, I think editing binary blobs (like images) would be just as fast as Rust, if I remember some of the research I did correctly. I don't have any sources on that, and it was a while back, so it's kinda irrelevant, I guess.