Live data from Hacker News

Branch Prediction and the Performance of Interpreters – Don’t Trust Folklore

hal.inria.fr

1–10 of 56 posts

Re: Branch Prediction and the Performance of Interpreters – Don’t Trust Folklore

#3
If my coworker would come to me and show me his results where he measured that the "Labels as Values" implementation is not need while "on his Haswell CPU the speedup is only 3%" I'd just ask "can it be guaranteed that the code you propose to revert to the plain switch will run only on that CPU?"

If not and the switch is in the performance sensitive place I'd keep the "Labels as Values" implementation.

There are many more CPUs in the world than "the latest Intel x86 CPU." Kudos for the developers of Haswell, but don't blindly trust the Inria researchers that tell you "Don’t Trust Folklore."

I also don't like that this research was "partially supported" by the European grant thus explained: "ERC Advanced Grants allow exceptional established research leaders of any nationality and any age to pursue ground-breaking, high-risk projects that open new directions in their respective research fields or other domains." (1)

1) http://erc.europa.eu/advanced-grants

Is ground-breaking, high-risk research discovering that the algorithm in the latest Intel processor matches the one other researchers (which I respect much more) discovered in 2006, and variant of which won more "branch prediction championships"? I'd say no.

At least they honestly write about the fact that the given algorithm is already known as highly efficient.

Re: Branch Prediction and the Performance of Interpreters – Don’t Trust Folklore

#4
post #3

If my coworker would come to me and show me his results where he measured that the "Labels as Values" implementation is not need while "on his Haswell CPU the speedup is only 3%" I'd just ask "can it be guaranteed that the code you propose to revert to the plain switch will run only on that CPU?" If not and the switch is in the performance sensitive place I'd keep the "Labels as Values" implementation. There are many…

While I somewhat agree with you, the real answer is assume nothing and profile. Always. But there's a catch. Things are getting a bit out of hand, there are just too many architectures and configurations.

I think modern consumer-oriented code should run at least well on Intel Nehalem - Skylake, AMD K10 - K12, ARM Cortex A7/A8/A9/A15/A53/A57/A72, Qualcomm Krait/Kryo.

Focus on 64-bit, but some attention should still be paid to 32-bit performance.

Number of actual targets is even worse, because cache and memory architecture vary so much. At least all those have 64-byte cache lines.

In high performance code, there's often the choice between memory and compute load balancing. What memory access patterns and layouts you're going to use - where do you want your bottlenecks? You can often reduce bandwidth requirements by computing more and vice versa.

Take Sandy Bridge for example:

While L1 and L2 cache sizes are fixed on Sandy Bridge, L3 cache varies between 1 - 20 MB.

Clock speeds vary between 1.0 to 3.6 GHz.

There are 1-4 memory channels, I believe they're usually arranged 64 byte granularity round robin. Say your access pattern is access every second 64-byte cache line vs. access every line. On 1 and 3 channel systems, both perform about same. When skipping 64 byte cache line on 2 channel system, effective memory bandwidth is equal to just 1 channel system. 4 channel system will behave like 2 channel one. The code might be bandwidth bottlenecked on 1-2 channel system and compute bound on 3-4 channel system.

Then you're going to hit DRAM page miss every... 1-8 kB? System dependant, of course.

To make the best choice for Sandy Bridge based systems, among other things, you need to know number of memory channels + their arrangement, amount of L3 cache and clock speed. On some Sandy Bridge CPUs you have a lot of time to do complicated data packing and unpacking, trying to just keep memory bandwidth usage down.

That was just one architecture. Now add all the other platforms in the mix. There are pretty many different instruction set extensions. If you don't use them properly, you can lose an order of magnitude of performance.

I think we'll need runtime code generation in the future. On system JIT/AOT also for traditionally compiled languages, such as C and C++.

Re: Branch Prediction and the Performance of Interpreters – Don’t Trust Folklore

#5
post #4
post #3

If my coworker would come to me and show me his results where he measured that the "Labels as Values" implementation is not need while "on his Haswell CPU the speedup is only 3%" I'd just ask "can it be guaranteed that the code you propose to revert to the plain switch will run only on that CPU?" If not and the switch is in the performance sensitive place I'd keep the "Labels as Values" implementation. There are many…

While I somewhat agree with you, the real answer is assume nothing and profile . Always. But there's a catch. Things are getting a bit out of hand, there are just too many architectures and configurations. I think modern consumer-oriented code should run at least well on Intel Nehalem - Skylake, AMD K10 - K12, ARM Cortex A7/A8/A9/A15/A53/A57/A72, Qualcomm Krait/Kryo. Focus on 64-bit, but some attention should still b…

> the real answer is assume nothing and profile.

They did profile, but what? Their "don't trust folklore" ("just 3% speedup") conclusion is valid only for one specific architecture and only for the most recent CPUs. As you say

> modern consumer-oriented code should run at least well on Intel Nehalem - Skylake, AMD K10 - K12, ARM Cortex A7/A8/A9/A15/A53/A57/A72, Qualcomm Krait/Kryo.

If I understand correctly, they themselves measure 30% speedup even only one generation before on Intel and they didn't measure any ARM or AMD.

It looks to me that "don't trust folklore" claim was possible only by ignoring all the processors you name.

And you are right, they also didn't show that they are aware of the differences inside of one generation (does the cheapest processor of the same generation behave the same?)

Re: Branch Prediction and the Performance of Interpreters – Don’t Trust Folklore

#6
tl;dr for those who don't want to read the paper in detail:

* Interpreters are conceptually a big switch(bytecode) statement in an infinite loop. They use various tricks to make it easier for the processor to predict the target of the next indirect branch

* This previously had a dramatic impact on performance, because branch mispredictions are very expensive and it was difficult for the processor to predict them accurately.

* Recent Intel architectures have improved branch prediction, so the aforementioned tricks no longer have a very big impact (on Haswell x86 processors specifically)

Re: Branch Prediction and the Performance of Interpreters – Don’t Trust Folklore

#8
post #3

If my coworker would come to me and show me his results where he measured that the "Labels as Values" implementation is not need while "on his Haswell CPU the speedup is only 3%" I'd just ask "can it be guaranteed that the code you propose to revert to the plain switch will run only on that CPU?" If not and the switch is in the performance sensitive place I'd keep the "Labels as Values" implementation. There are many…

> Is ground-breaking, high-risk research discovering that the algorithm in the latest Intel processor matches the one other researchers (which I respect much more) discovered in 2006, and variant of which won more "branch prediction championships"? I'd say no.

That appears to be a pretty reasonable criticism of the process by which the grant was awarded.

My somewhat unfair characterisation of this research from skim reading the abstract and conclusion is: "we point out that the understanding in the academic literature is lagging behind the understanding already built into systems that are sold commercially and are in operational use".

edit:

There's something slightly humorous in considering the grant-allocation process itself as some kind of optimisation problem:

Problem (GA) : How do we best allocate resources to promote high-risk, ground-breaking research?

...and then observing that grant resources have been allocated to perform research on another piece of optimisation that already seems to have happened.

I wonder if one could obtain an ERC Advanced Grant to study the effectiveness of the current process by which ERC Advanced Grants are awarded, and suggest improvements? It is plausible that such a study could be very valuable and yet not have much political support.

Re: Branch Prediction and the Performance of Interpreters – Don’t Trust Folklore

#9
post #8
post #3

If my coworker would come to me and show me his results where he measured that the "Labels as Values" implementation is not need while "on his Haswell CPU the speedup is only 3%" I'd just ask "can it be guaranteed that the code you propose to revert to the plain switch will run only on that CPU?" If not and the switch is in the performance sensitive place I'd keep the "Labels as Values" implementation. There are many…

> Is ground-breaking, high-risk research discovering that the algorithm in the latest Intel processor matches the one other researchers (which I respect much more) discovered in 2006, and variant of which won more "branch prediction championships"? I'd say no. That appears to be a pretty reasonable criticism of the process by which the grant was awarded. My somewhat unfair characterisation of this research from skim…

> understanding in the academic literature is lagging

Even that were too much to claim as the "branch prediction championships" happened on an "academic" place:

IEEE/ACM International Symposium on Microarchitecture

http://www.jilp.org/cbp/

http://www.microarch.org/micro37/

also note the sponsors.

Re: Branch Prediction and the Performance of Interpreters – Don’t Trust Folklore

#10
post #4
post #3

If my coworker would come to me and show me his results where he measured that the "Labels as Values" implementation is not need while "on his Haswell CPU the speedup is only 3%" I'd just ask "can it be guaranteed that the code you propose to revert to the plain switch will run only on that CPU?" If not and the switch is in the performance sensitive place I'd keep the "Labels as Values" implementation. There are many…

While I somewhat agree with you, the real answer is assume nothing and profile . Always. But there's a catch. Things are getting a bit out of hand, there are just too many architectures and configurations. I think modern consumer-oriented code should run at least well on Intel Nehalem - Skylake, AMD K10 - K12, ARM Cortex A7/A8/A9/A15/A53/A57/A72, Qualcomm Krait/Kryo. Focus on 64-bit, but some attention should still b…

The fact that the performance of an implementation varies significantly depending on the actual CPU could already be deduced from some of the Ertl papers.

Moreover, given that one uses specifically a bytecode interpreter and not a JIT is generally the sign that the interpreter is to be used on multiple platforms. "Optimizing" in this context simply means (almost) nothing.

The obvious conclusion is to not care too much about raw performance and focus instead on ease of interfacing with libraries, and to make it easy to add primitives/instructions to your VM. With the idea that if your interpreter is too slow, you just rewrite the critical parts in native code.

Post reply on HN