Causal Profiling Rust Code

Wherein we look at how speeding up a bit of Rust code can make the whole program faster – or slower.


My take away from that Causal Profiling presentation was that rearranging ones code and/or data layout and so on can dramatically change a program's performance. So much so that it can be hard to tell if the change one has made actually had an effect or whether the performance differences one sees are just an artifact of some unaccounted side effect.

Hence all the effort into randomizing things over many runs and looking for a statistically meaningful result.

But wait, if the changes in performance I make to my code are lost in the noise what I actually want is for the causal profiler tool to repeatedly rearrange my code and then deliver a modified binary that shows the best performance.

BINGO I get optimization for free!

Or did I get the wrong end of the stick with all this?


The problem with this approach is that you get an optimization that will only work on your machine under that exact same workload and non-randomized circumstances. If you want that, use Profile-guided optimization, which has recently become available in Rust. No causal profiling necessary.

What you want is an optimization that gives you benefits regardless the machine, workload and circumstances.

Ah but, that is key to my suggestion, I want a build that is optimal for my machines. If causal profiling can find an optimal arrangement of my code and data for those, with no actual source tweaking required, that would be great. Especially as the statistics shown in that presentation indicate show that large gains are possible with just that.

Note the plural there. If I happen to have a data center or super computer with thousands of identical nodes I want things optimized for those. I don't care about anyone else's different machines and operating systems etc.

As far as I understand profile guided optimization is aimed at finding the hot spots in my code and optimizing things for those parts. Which sounds great. Now let's have causal profiling on top of that!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.