News for hackers. Stuff that matters.
Re:Perl 11 by koolba on Tuesday October 23, 2018 @07:18PM (#18288350)
I’m not familiar with the details but I’d wager they’re referring to JIT compilation which can exceed precompiled native code as it can (in theory) account for actual usage patterns.
Re:Perl 11 by jerf on Tuesday October 23, 2018 @07:40PM (#18288460)
That was a fun theory 15-20 years ago. We've now got piles of evidence it doesn't work that way. JITs can accelerate slow languages, at a stiff RAM penalty, but they still remain noticeably slower than faster languages.

Claims to the contrary at this point will require concrete demonstration. Starting from the union of Perl 5 and Perl 6 is just about the worst starting point for that goal I can imagine. (Not necessarily because "Perl sucks", but because any such solution to that problem is probably going to require writing the language with that goal from day 1, not taking existing languages as a given. Or, like LuaJIT, cutting things that don't fit. And between Perl 5 and Perl 6, there are sooooo many "things"....)

Re:Perl 11 by hyperpape on Tuesday October 23, 2018 @08:07PM (#18288580)
I'm with you about the overall point that Perl5/6 are not going to get C/C++ speed.

However, on the specific point, why do you think the JIT forces high memory usage? In the case of Java, my perception is that it's the pervasive use of boxed types everywhere and a standard library that's past its sell-by-date that drives bloated memory usage.

Maybe my sense of things is a little skewed by my work: I work on server processes that use gigs of memory. There, the resources for the JVM/JIT itself usually use vastly less memory than the java objects contained in the heap (probably 10x, and this is for a monolith with thousands of classes).

Re:Perl 11 by cryptos on Wednesday October 24, 2018 @07:45AM (#18291533)
The JVM uses the memory to optimize the garbage collection, so it is a tradeoff between memory usage and speed (favoring the latter).
Re:Perl 11 by richardwhiuk on Tuesday October 23, 2018 @10:04PM (#18289111)
It's the pervasive requirement of a dynamically typed language, not the JIT per say.
Re:Perl 11 by snapdangle on Wednesday October 24, 2018 @01:15AM (#18289892)
And yet Perl 6 has been droppping their performance floor by enormous factors, with a lot of room for improvement still.

Everyone always shrugged at me when I explained that Perl 6 was designed to be able to be fast, with the ability to outstrip Perl and even other languages.

And now that it's happening? They are still shrugging, but its the uncomfortable shrug of someone trying to shake off an inconvenient truth.

Re:Perl 11 by jerf on Wednesday October 24, 2018 @09:41AM (#18292297)
"And yet Perl 6 has been droppping their performance floor by enormous factors, with a lot of room for improvement still."

Considering the literally-unusable performance that Perl 6 has had within fairly recent memory, getting a lot faster hasn't been that impressive.

Plus, goals aren't results. I'll believe Perl 6 is natively fast when somebody actually shows it outcompeting, say, Rust, on some non-trivial task, written in the native idiom. No fair just sitting there in a loop and adding integers, which is easy-mode for a JIT. Show me a real program, that I didn't have to write in a magical subset of Perl 6 to get the performance (a problem Javascript has, "fast JIT'ed Javascript" is a mysterious and ever-changing subset, where your performance can be tanked at any moment by the smallest of changes), and don't tell me about how it's a 100x faster than last year, show me how it's faster than Rust now. Or, heck, just show me beating Go. I'll believe when I see it. And I will believe it when I see it. I have no problem with that. But I've seen the whole "as good as or better than C" claims a lot over the years, and the people making those claims are batting nearly 0.000. (Rust is pretty much the only language with a chance.)

You seem to believe in the existence of a bunch of people who have somehow wrapped their identity around hating Perl 6. That's not it; what you're seeing is that the Perl 6 community burned through their goodwill literally years ago, and now people are just exasperated when the topic comes up. If it helps you to identify as some sort of persecuted minority, hey, go nuts [1], it's a very popular option nowadays, but the Perl 6 community is years past the point where mocking the potential customers into trying it is going to do any good. You're going to need hard evidence... really, really hard evidence, probably rather a lot of it, more than you'll probably think is fair but such is the hole the Perl 6 community has dug itself into over the years... to convince people, not mockery.

[1]: Actually I think it's a terrible and very unhealthy idea; you'll find none of the collected ancient wisdom of humanity will tell you that constantly nursing a persecution complex is the way to wisdom or happiness. But such is the zeitgeist of the era.

Re:Perl 11 by lizmat on Wednesday October 24, 2018 @10:07AM (#18292517)
> You seem to believe in the existence of a bunch of people who have somehow wrapped their identity around hating Perl 6.

You only have to go to PerlMonks to find them. It's not that hard.

> the Perl 6 community burned through their goodwill literally years ago

That may be so, but most Perl 6 people from that era, either have left or have reverted to lurking mode. The current Perl 6 community mostly consist of people who have become active during the last implementation attempt, based on 6model and MoarVM. And who are focused on results.

> You're going to need hard evidence

Working on it :-). https://twitter.com/zoffix/status/1045623538345017344 shows an object creation benchmark compared to Perl 5 (Perl 6 having become faster than Perl 5), and a "real world" benchmark that's been running for 4+ years: https://tux.nl/Talks/CSV6/speed.log

Yes, it's still not as fast as one would like it to be. Still, as said before, Rakudo on MoarVM is designed to be able to support runtime optimizations. If you like to find out more about how these optimizations are done, check out Jonathan Worthington's blog: https://6guts.wordpress.com

Re:Perl 11 by petre on Wednesday October 24, 2018 @03:21PM (#18295527)
> I'll believe Perl 6 is natively fast when somebody actually shows it outcompeting, say, Rust, on some non-trivial task, written in the native idiom.

If it beats Java then it's fine. I do not expect a VM language to be faster than machine code. Rust is also overhyped. I did some of my own benchmarks and Go and D turned out faster than Rust, or at least their maps/associative arrays are faster that Rust's HashMap. Also, I won't use stuff that is not in the stdlib in the benchmarks.

Re:Perl 11 by steveklabnik on Wednesday October 24, 2018 @04:48PM (#18296233)
> I did some of my own benchmarks and Go and D turned out faster than Rust, or at least their maps/associative arrays are faster that Rust's HashMap. Also, I won't use stuff that is not in the stdlib in the benchmarks.

Rust's HashMaps are intentionally slow by default. You could use a different hash function with them if you want different properties. That means writing your own if you don't want a known-good implementation, of course, but this is expected and not really representative of Rust generally, which uses associative arrays pretty infrequently.

Re:Perl 11 by microtherion on Wednesday October 24, 2018 @09:47AM (#18292359)
Correct me if I'm wrong, but isn't Perl 6 still considerably slower than Perl 5?
Re:Perl 11 by cygx on Wednesday October 24, 2018 @01:51PM (#18294716)
As a rule of thumb, that's probably still accurate. But there are specific areas where Rakudo on MoarVM already outperforms the Perl5 interpreter (eg an object creation benchmark was mentioned elsewhere).

I suspect the scale will eventually tilt in Perl6's favour, but is has been slow going...

Re:Perl 11 by village-idiot on Wednesday October 24, 2018 @08:41AM (#18291865)
A lot of them are probably shrugging because they have 0 interest in Perl, and you telling them more about Perl is not going to change their mind.

I personally could not care less about Perl 6’s speed, I will never use it anyways.

Re:Perl 11 by FridgeSeal on Tuesday October 23, 2018 @10:01PM (#18289093)
> JITs can accelerate slow languages, at a stiff RAM penalty, but they still remain noticeably slower than faster languages.

The Julia language would like a word.

It compiles to native machine code via LLVM, which is the same backend that a lot of statically typed languages use, and bar it's very first run, it can run blindingly fast: I've been using it instead of Python at work for Data Science things and it's been great.

Re:Perl 11 by kibwen on Tuesday October 23, 2018 @10:36PM (#18289265)
As I understand it, Julia's current implementation is not a JIT in any comparable sense to the JVM. Julia's JIT does not use any runtime information to optimize code; it's literally just statically compiling each function on-demand as they are encountered. You would get equivalent runtime performance by having a separate up-front compiler step, as C has. And actually, this sort of implies that Julia doesn't do inlining, the mother of all optimizations, which would mean that you'd be sacrificing quite a lot of runtime performance compared to an up-front compiled implementation.

https://discourse.julialang.org/t/notes-on-the-julia-compile...

Re:Perl 11 by byt143 on Tuesday October 23, 2018 @11:40PM (#18289534)
Actually Julia is aggressively inlined because it's easy to statically determine function calls at compile time...that's why the libraries are able to use such nice abstractions.

It's already ahead of time compilable, just needs some work to emit smaller binaries and cover some corner cases

Re:Perl 11 by kibwen on Wednesday October 24, 2018 @09:31AM (#18292201)
Good to know, thanks.
Re:Perl 11 by jashmatthews on Wednesday October 24, 2018 @01:16AM (#18289898)
> As I understand it, Julia's current implementation is not a JIT in any comparable sense

Going straight to machine code via baseline compilation is a common JIT technique. Until a couple of years ago, V8 compiled everything.

Re:Perl 11 by kibwen on Wednesday October 24, 2018 @09:28AM (#18292183)
Baseline compilation is fine, that wasn't what I was referring to. I the context of this thread, the long-awaited promise of JIT is the ability to profile running code to dynamically determine the hot portions and re-optimize on the fly, and do this continually for the entire runtime of the program. This is what people mean by "things that are impossible for a static compiler to do" (though PGO is a decent approximation), and the basis of all discussions that begin with "actually, Java can be faster than C". This is not to say that Julia does not satisfy the definition of a JIT, only that using Julia as an example of this principle appears to be mistaken. Julia is not fast because it dynamically re-optimizes, it's fast because it uses a mature C compiler backend.
Re:Perl 11 by ihnorton on Wednesday October 24, 2018 @08:27AM (#18291800)
Julia does not have a tracing JIT right now, but does use runtime information in order to JIT specializations based on (often inferred) method argument types.
Re:Perl 11 by jerf on Wednesday October 24, 2018 @09:30AM (#18292195)
For your point to be a disagreement, you'd first have to agree that Julia is a "slow language", that is sped up by a JIT. Would you agree with that? Or is it an example of a sort of language that I referenced, one that was designed to perform well from the beginning that may use some technology that looks like a JIT (though as others pointed out, not necessarily really the same)?
Re:Perl 11 by koolba on Tuesday October 23, 2018 @08:29PM (#18288689)
I didn’t mean to say I think it’s possible in this particular case for arbitrary code (particular for something as wild as Perl!). I was merely explaining (what I think) is the logic behind the approach.

The only circumstance I can see where a true JIT will beat out native code is when there are many possible paths of execution such that all may not be possible to evaluate at compile time. In that case it’s not even really interpreted vs compiled so much as static vs adaptive.

Re:Perl 11 by gnulinux on Tuesday October 23, 2018 @07:56PM (#18288532)
This is said every single time when "JIT" is mentioned but I've never heard an argument how that might be possible. For all I know you'll have two problems (1) your heuristic should be so damn fast that it compensates for the runtime analysis time, this is non-trivial for JIT but trivial for AoT since runtime analysis cost is 0 (2) you need to tell us a story about how can this heuristic be so specialized that I cannot write my program, profile it on some training data (bunch of program inputs), profile and optimize (gcc and llvm can do this trivially). I never saw any code solving (1) or (2). Do we have any evidence JIT being faster than AoT? No, I see no such evidence. Even the most cutting edge JIT compilers like LuaJIT or JVM are lightyears behind gcc, llvm, rustc etc... Do we have any evidence we can perform more optimizations at runtime compared to compile-time, no I don't see any evidence. JIT was a nice, powerful, avant-garde idea that could change everything, but I don't think it turned out to be the superstar we all thought it'd be.
Re:Perl 11 by EdiX on Wednesday October 24, 2018 @03:27AM (#18290360)
>This is said every single time when "JIT" is mentioned but I've never heard an argument how that might be possible

I'll explain it but you have to pretend that we are in the 90s, so before you continue reading click on this link:

https://www.youtube.com/watch?v=_JphDdGV2TU

"Modern" CPUs achieve some of their speed by executing multiple instructions in parallel, using a pipeline: the first stage fetches an instruction from memory, hands it to the second stage that decodes it but while the decoding is taking place the first stage will have already started fetching the next instruction from memory. Conditional jump instructions of course ruin everything, because you need to know the result of their evaluation, before you can decide which instruction is the "next" one.

"Modern" CPUs work around this by always assuming that the jump is never taken and then, if it turns out that the jump does get taken, rolling back the partial work that they did.

As it turns out the vast majority of conditional jumps in a program always go the same way, i.e. any given conditional jump is either always taken or never taken. If the compiler knew which way the condition went it would be possible to lay out the program in a way that jumps are almost never taken, for maximum performance.

A static compiler can't do this but with a JIT you can run the program in bytecode a bunch of times and then use the information you gathered to lay it out in the best way possible.

All that I've said is 100% true and empirically verifiable. The reason this didn't work out is that in the early-2000s all x86 CPU manufacturer started adding this specific optimization directly inside the CPU. They started keeping branch counters and using them to guess which way conditional jumps were more likely to go.

There's other optimizations that a JIT compiler can do and a static compiler can't, but the story is similar. Big x86 manufacturers can do almost anything a JIT compiler can do and that's why the technology is essentially obsolete.

There's still some value in distributing a single binary that executes at near-native speed everywhere, but that's basically it.

Re:Perl 11 by chrisseaton on Tuesday October 23, 2018 @08:22PM (#18288652)
A JIT can do all the optimisations that a static compiler can, and then of top of that it can do additional optimisations that a static compiler can't.
Re:Perl 11 by marcosdumay on Tuesday October 23, 2018 @09:14PM (#18288904)
> A JIT can do all the optimisations that a static compiler can

As long as it has <100ms of compilation time.

Re:Perl 11 by chrisseaton on Tuesday October 23, 2018 @09:18PM (#18288928)
Why do all JITs need to run in <100ms?

If you run your trading app once a day, all day, and warm it up for an hour first, and want max speed, why do you care if it takes a few seconds to compile?

Re:Perl 11 by bquinlan on Tuesday October 23, 2018 @09:48PM (#18289047)
If that is the scenario that you care about, then you can use profile guided optimization in statically compiled languages.

Clang has instructions on how to do so here: https://clang.llvm.org/docs/UsersManual.html#profile-guided-...

Re:Perl 11 by chrisseaton on Tuesday October 23, 2018 @10:18PM (#18289180)
But that only gives you info from previous runs. A JIT profiles the current run. That's strictly more information than an AOT compiler has.
Re:Perl 11 by Retra on Tuesday October 23, 2018 @11:15PM (#18289422)
If you're running code all day long and profiling it dynamically the whole time, then you're going to pay for it. There is overhead to JIT, and there is overhead to profiling. There is no overhead for a statically compiled program, no matter how you profile it.
Re:Perl 11 by gnulinux on Wednesday October 24, 2018 @09:20AM (#18292122)
I still need evidence that my real time trading app running an entire gcc in it makes it faster. I have no problem with JIT in theory, everything you say makes sense. I've never seen this trend in practice though. Either the optimizations you're talking about can be utilized too rarely, or they are too complex that most JITs don't implement, or they're too expensive that it doesn't give any net gain.
Re:Perl 11 by zzzcpan on Wednesday October 24, 2018 @09:51AM (#18292391)
Well, it doesn't actually make sense in theory. While JIT theoretically can profile a current run it also adds a JIT related runtime overhead. It needs to waste a lot of resources on both profiling and recompilation to make use of any new information. That's always going to be strictly slower than PGO techniques, with basically hand picked optimizations for each application and zero overhead.
Re:Perl 11 by marcosdumay on Tuesday October 23, 2018 @11:02PM (#18289373)
Yes, that's strictly more information. You still better collect it quickly, as you are compiling your functions each time they run.

Besides, people rally don't like that warming-up period. But it's not the current bottleneck.

Anyway, JIT has a great potential. Just not for desktop software, or network services, or your trading app. It can be great for scientific computing, for example. But that's potential; currently it's not any good on practice.

Re:Perl 11 by pjmlp on Wednesday October 24, 2018 @03:10AM (#18290293)
Well, Android team decided that AOT introduced in Android 5 was a mistake and they went back to a mix of first level interpreter handwritten in Assembly => JIT + PGO => AOT + PGO(taken from JIT) when idle.

Also the large majority of modern Windows software is actually written in .NET, with small C++ pieces.

Re:Perl 11 by cygx on Wednesday October 24, 2018 @01:32PM (#18294547)
It's true that AOT compilers can get most of the benefits of JIT compilers by leveraging profile guided and link-time optimization. In principle, we could get rid of shared libraries, ship LLVM bitcode instead and statically compile everything, enabling cross-library optimizations - but so far, we tend to not do that...
Re:Perl 11 by ComputerGuru on Tuesday October 23, 2018 @08:16PM (#18288617)
LuaJit comes close to pulling this off in some cases (and does in a select few), but obviously not across the board in general use.