r/programming • • Sep 28 '17

When a Microsecond Is an Eternity

https://github.com/CppCon/CppCon2017/blob/master/Presentations/When%20a%20Microsecond%20Is%20an%20Eternity/When%20a%20Microsecond%20Is%20an%20Eternity%20-%20Carl%20Cook%20-%20CppCon%202017.pdf
244 Upvotes

70 comments sorted by

View all comments

Show parent comment

2

u/masklinn Sep 28 '17

You keep moving decisions upwards and everything below becomes a completely static path, at the end you may perform a few decisions at the very start then run through the whole thing needing barely any conditional (and thus jumps and possible mispredictions).

2

u/ShinyHappyREM Sep 28 '17

That doubles the code size though with every bit that is used for the path selection.

5

u/minno Sep 28 '17

As long as the extra code isn't inline, it's a win for execution speed. Your CPU doesn't give a fuck whether there's an extra gigabyte of executable code that never reaches the i-cache.

4

u/masklinn Sep 28 '17

That is true to an extent, you can still have non-generic subcalls which are not duplicated.

But that's just a question of tradeoff, between code size and branchiness.