pervognsen ,
@pervognsen@mastodon.social avatar

Digging through old stuff, here's a fairly extreme example of branch predictor training effects in a benchmark of Robin Hood linear probing vs conventional linear probing. Look at the branch misses for 1 vs 1000 outer loop iterations for RH (and the impact on wall clock time): https://gist.github.com/pervognsen/e818251d52f725db7c67e562577a12f6

amonakov ,
@amonakov@mastodon.gamedev.place avatar

@pervognsen Is that Rust's built-in perf_event interface in action for {branch,cache} miss counts?

pervognsen OP ,
@pervognsen@mastodon.social avatar

@amonakov It's not built-in. It was a third-party crate, probably this: https://docs.rs/perf-event/latest/perf_event/

pervognsen OP , (edited )
@pervognsen@mastodon.social avatar

Yes, the RH bench run for 16k lookups (after 1000 outer-loop iterations) is literally branch mispredicting only 45 times (!!!). It has almost perfectly learned the probe length distribution of the 16k keys in order and also which are hits and misses. Once you've seen enough of this stuff in your own microbenchmarks, you stop trusting anyone else's if they have even the slightest signs of potential problems based on their code structure, e.g. outer loop over the same too small/too regular data.

pervognsen OP ,
@pervognsen@mastodon.social avatar

(And counterintuitively, if you haven't worked through this stuff before, the fact that the data is randomly generated can actually make it easier for the branch predictor since it presents a stronger "signature" in the global branch history. The problem is that you randomly generate the data once and then do 1000 outer-loop runs of the workload on that data.)

pervognsen OP ,
@pervognsen@mastodon.social avatar

My hypothesis at the time (it's been a while) was that the much tighter probe length distribution for RH is why it sees a much stronger training effect here.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • tech
  • kbinEarth
  • testing
  • interstellar
  • wanderlust
  • All magazines