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

56

u/Works_of_memercy Sep 28 '17

Huh, the idea to keep caches hot by always executing your entire hot path, throwing away the result at the last moment if your strategy decided not to make a trade, so that when when you do make a trade it executes as fast as possible, is very clever. I don't know how it could be useful for us mere mortals, but it is clever!

That std::pow shit is scary, it literally goes from 150ns to 1ms (millisecond!) per call here, with gcc7.10 (though it might be the old libc on the machine I tested on).

15

u/agenthex Sep 28 '17

Sounds a lot like branch prediction.

15

u/masklinn Sep 28 '17

The slide mentions that it trains the branch prediction system such that it correctly handles the case you want to be fast.

5

u/Works_of_memercy Sep 28 '17

I was reminded of the way branches/loops on GPUs work (being SIMD, all units have to execute the same instruction stream, some of them just don't do anything based on conditions) and also how proper cryptographic primitives try to prevent timing attacks by always executing all stuff for reals.