News for hackers. Stuff that matters.
Re:Iris: Fast back-end web framework for Go by andkenneth on Tuesday June 21, 2016 @05:36AM (#11944576)
Go has high level constructs like python, C# or Java. However, it compiles down to machine code directly, like C. This is much faster than C# or Java, which compile to an intermediate interface (CLR and java bytecode respectively, which then run in a VM), and miles ahead of Python, which interprets from the source every single time the program is run.

The closest language to go would probably be C++, and the language designers were quoted saying the main driving force behind go was to replace C++ due to it's complexity.

Re:Iris: Fast back-end web framework for Go by pcwalton on Tuesday June 21, 2016 @01:21PM (#11947461)
> This is much faster than C# or Java, which compile to an intermediate interface (CLR and java bytecode respectively, which then run in a VM)

No. Both C# and Java use JITs, and their JITs have been carefully tuned to focus on hot spots. By not having a JIT, Go (in the 6g/8g/gccgo implementations) loses some important optimizations that are very helpful for making virtual-heavy languages like Go faster. JITs enable on-stack replacement, bailouts, and self-modifying code, which enable speculative devirtualization and (polymorphic) inline caching, just to name two techniques. These are very important optimizations that generally you can only get reliably in an ahead-of-time setting with profile-guided optimization, which Go 6g/8g don't have (and PGO is kind of a worse version of what good JITs do anyway).

The true benefits of AOT are reduced startup time and a greater tolerance for slower compilation, allowing for more sophisticated compiler optimizations—instruction scheduling, alias analysis, range analysis, etc. But Go 6g/8g are focused on fast compilation and omit most of those optimizations anyway.

Re:Iris: Fast back-end web framework for Go by ngrilly on Wednesday June 22, 2016 @06:58AM (#11952781)
> By not having a JIT, Go loses some important optimizations that are very helpful for making virtual-heavy languages like Go faster.

How does Rust work in this regard? By avoiding virtualization, and compiling each function to many specialized variants corresponding to each possible permutation of input and output types?

Re:Iris: Fast back-end web framework for Go by eddyb on Wednesday June 22, 2016 @08:16AM (#11953249)
With generics, yes, like C++ templates: each combination of parameters results in one instance.

However, you can opt into using trait objects instead, which do use virtual calls.

Re:Iris: Fast back-end web framework for Go by ngrilly on Wednesday June 22, 2016 @04:46PM (#11956871)
Is pcwalton saying that a JIT compiler is more adequate for a "virtual-heavy" language like Go (to use devirtualization with inline caching and bailout), and an AOT compiler is more adequate for languages like Rust and C++ that mostly use code specialization?
Re:Iris: Fast back-end web framework for Go by kibwen on Thursday June 23, 2016 @12:53AM (#11958918)
It's not quite as clean-cut as that, though it is self-evident that optimizing at runtime (e.g. JIT) is the only recourse for optimizations that are otherwise reliant on runtime information (e.g. dynamic dispatch/virtual calls). Go does have an advantage over Java in that it prefers static semantics (pcwalton's assertion that Go is "virtual heavy" should likely be taken as relative to Rust/C++), so has less to benefit from devirtualization, and thus less of an argument to go the JIT route (which would take monumental engineering effort).

I believe pcwalton's points are that 1) running in a virtual machine does not imply that a language is slow (though I bet he'd agree with you that JIT introduces substantial memory overhead), and 2) Java, specifically, is not slow, thanks to a highly-tuned JIT.

Re:Iris: Fast back-end web framework for Go by ngrilly on Thursday June 23, 2016 @03:07AM (#11959346)
Thanks! That's exactly what I wanted to know.
Re:Iris: Fast back-end web framework for Go by ngrilly on Wednesday June 22, 2016 @06:48AM (#11952747)
You forgot to mention a significant another drawback of most JIT implementations, compared to AOT: the bigger memory footprint.
Re:Iris: Fast back-end web framework for Go by fulafel on Tuesday June 21, 2016 @09:46AM (#11945525)
Compiling Python down to machine code and eliminating the VM interpreter loop does not speed it up dramatically (iirc ~30%), it has been tried. It's largely because Python is a dynamically typed language with a lot of runtime dispatch, and Go is a statically typed language with less runtime dispatch.
Re:Iris: Fast back-end web framework for Go by pjmlp on Tuesday June 21, 2016 @08:05AM (#11945055)
> This is much faster than C# or Java, which compile to an intermediate interface (CLR and java bytecode respectively, which then run in a VM).

Except there are things like ExcelsiorJET, CodenameONE, J9, .NET Native, CoreRT, Mono -AOT, IL2CPP.

As usual, language and implementation aren't the same thing.

Re:Iris: Fast back-end web framework for Go by insertnickname on Tuesday June 21, 2016 @05:42AM (#11944601)
IIRC, Go code compiled with the gc compiler has about the same performance as Java running on the JVM. Surely Go isn't much faster than Java.
Re:Iris: Fast back-end web framework for Go by ptman on Tuesday June 21, 2016 @05:58AM (#11944655)
You are mostly correctly. There are some things that Go can do to perform better than Java. Go arrays have one less step of indirection compared to Java arrays. And Go allows for more control about the memory layout of structs/classes and arrays.
Re:Iris: Fast back-end web framework for Go by kasey_junk on Tuesday June 21, 2016 @07:53AM (#11945015)
But it also doesn't perform as well with large data sets and has less compiler optimizations and no JIT.

Saying Go is much faster than Java is nonsense.

Re:Iris: Fast back-end web framework for Go by thwd on Tuesday June 21, 2016 @12:39PM (#11947039)
The speed at which a big data set is processed has nothing to do with the language or its' compiler. It's the way in which the data set is streamed through memory by a particular program. Go offers two standardized interfaces for this, `io.Reader` and `io.Writer`. Also, if the data set can be batched, it's trivial to parallelize processing in Go, while it's a big hurdle in Java.

A JIT is not a performance feature per-se, either. It can be used for runtime code-optimization and -specialization which can improve performance. Some JVM implementations try and do this as well as they can automatically. The stuff they optimize, though, is exactly the kind of indirection that doesn't exist in Go in the first place.

The optimizations `javac` does are one of the few things that allows Java code to run at a competitive speed. And they're mostly trading space for performance, hence the unusually large memory footprint of Java applications.

Re:Iris: Fast back-end web framework for Go by kasey_junk on Tuesday June 21, 2016 @01:21PM (#11947459)
The big data set stuff I generalized around has more to do with the runtimes involved. Most JVM gc systems for instance are moving collectors while the golang one isn't (or wasn't last I looked). This can cause slow downs in comparison to a comparable GC environment especially around large data sets in long running environments.

"And Go allows for more control about the memory layout of structs/classes and arrays." Is an absolutely true statement, and it means that for some classes of problems (namely systems that prioritize GC latency for throughput) golang might be faster. The opposite is also true, especially with regard to large interdependent data sets, the golang runtime handles those worse than most JVMs.

I'd also completely disagree with your statement "Also, if the data set can be batched, it's trivial to parallelize processing in Go, while it's a big hurdle in Java." Especially with regard to "fast". There are more & better high performance concurrency libraries in Java than there are in go.

All that said, I was really reacting to this line "This is much faster than C# or Java, which compile to an intermediate interface" which is utter nonsense.

In the end, talking about performance in such large grained ways is usually not valuable but I'm willing to say that golang performs in the same category of performance as most jvms and that calling go faster than java is nonsense unless you speak about very specific cases.

Re:Iris: Fast back-end web framework for Go by cakoose on Tuesday June 21, 2016 @06:29AM (#11944739)
There are two things here -- how fast can a language be in theory vs how fast a particular implementation is.

Interpreters are typically slower (though simple to write and portable). The standard Python/Ruby/PHP implementations are interpreters. (The Python interpreter doesn't interpret from source every time, though; it usually uses the bytecode from previous runs.)

Implementations that generate machine code are more complicated and less portable, but have the potential to be faster. However, while compiling "down to machine code directly" can help startup time, it has little to do with what allows a language to be fast. What matters is whether it's possible to generate efficient machine code.

Static typing, for example, allows a compiler (ahead-of-time or JIT/VM) to generate more efficient machine code [1]. The ability to monkey-patch code -- which is common in many dynamic languages -- makes things harder for a compiler.

That said, there are compilation techniques to make dynamic languages pretty fast -- much faster than the standard Python/Ruby/PHP interpreters. For example, Javascript VMs have gotten 10x (or more?) faster over the last 5 years. (One of the big ideas: <https://en.wikipedia.org/wiki/Inline_caching>.)

A great example of all this is Facebook's PHP compiler. The first version would compile to machine code ahead-of-time, but it wasn't that much faster than the standard PHP interpreter (and definitely slower than the Firefox/Chrome Javascript VMs). They eventually switched to a JIT compiler, which is a better strategy for a dynamic language. Later, they transitioned to statically-typed sorta-PHP-compatible language called Hack, which allows for even more efficient machine code.

[1] There are different levels of static typing, too. For example, Go is statically typed but doesn't have generics. A C# generic data structure can be converted to more efficient code than a Go "interface{}"-based data structure.

Re:Iris: Fast back-end web framework for Go by weberc2 on Tuesday June 21, 2016 @01:18PM (#11947424)
> The ability to monkey-patch code

"The liability to monkey-patch" in my opinion. :p

Re:Iris: Fast back-end web framework for Go by TheHydroImpulse on Tuesday June 21, 2016 @08:41AM (#11945202)
The early version of hiphop (Facebooks php compiler) would compile PHP into C++. It was really interesting how they went from C++ to now a full featured JIT.
Re:Iris: Fast back-end web framework for Go by cakoose on Wednesday June 22, 2016 @08:58PM (#11958206)
Right. But just to be clear, C++ was an implementation detail. You could treat the entire toolchain as a black box that read in PHP code and produced a single executable binary.