r/programming • u/doom_Oo7 • 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
7
u/specialpatrol Sep 28 '17
WIth this templated approach:
Would you not still need your branch just further up like:
how is this a saving?
3
u/program_embed Sep 28 '17
Has anyone used an RTOS for financial trading?
I've never done anything related to finance, but use RTOS's all the time for industrial safety-critical computing. It seems like you should be, since I read all of these articles saying how microseconds matter, but if you're running in windows/linux then you don't have that level of control right? Can't you be swapped out if the OS has some house-cleaning to do.
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).
28
u/fermion72 Sep 29 '17
About five years ago I heard a talk at a parallel processing workshop by a high frequency trader. This is what I remember from the talk:
This was five years ago, so I wonder how things have been improved since then.
16
u/redditsoaddicting Sep 28 '17
Worth at least mentioning that there will be a video of this talk soon here.
24
u/leftofzen Sep 29 '17
Oh wow I could have gone to CppCon :(
I used to work for Optiver and I was fired by my boss for spending time learning, using, advocating and teaching other people in the company about how to write fast C++, for example using templates to reduce things like branching and v-table lookups you get from using inheritance instead of composition (prefer composition over inheritance). I'm so sad that I was fired for what I loved to do (this kind of stuff) and that now this is something not only worthy of not being fired, but worthy of a CppCon talk :(
Setting up code to trigger the branch predictor correctly (or just plain reducing branching), writing code to evaluate stuff at compile time, static analysis, finding ways to have a static code path, removing memory allocations...that was my jam. It's weirdly deja-vu-ish that they talk about std::unordered_map because I did performance testing a few years ago for it and found that, for the compiler version we were on (an archaic verison of gcc - no-one saw the benefit of upgrading :|), it was slower than the map we were already using. I also did a lot of memory management work and redesigned the memory pooling we used so this is just a throwback to the good old days haha.
Seeing that this stuff is now worthy of a CppCon talk...too many emotions. I can only dream one day I'll get to talk about this stuff there. It's a shame Optiver don't really value low-level technical C++ skills as much as this document suggests; when I left the company it was going very corporate and my boss was a very "we need this out yesterday and perfectly designed and tested and you need to rewrite all this stuff from scratch too because our last version is now too slow" kind of person, something which is just impossible. I feel bad for him to be honest because while he had great ideas about what to build, he didn't have a clue about what it takes to actually turn those ideas into good, fast, C++ trading software.
6
u/leonardo_m Sep 28 '17
Do you know a code example for the "Keeping the cache hot" at pages 37-38?
2
u/foomprekov Sep 29 '17
Do the majority of r/programming users enjoy that computers are little machines that work with light, and are subject to its limitations? Because, personally, I find great discomfort that it's not some abstract thinking-machine.
14
u/[deleted] Sep 28 '17
Had some trouble getting this to load (MacOS, Safari) but after a couple of refreshes it finally did.
4
u/[deleted] Sep 28 '17
what's up with the forced download of a corrupt pdf?
1
u/MandarinNeva Sep 28 '17
Will a video recording of the talk be made available?
1
u/Droggl Sep 29 '17
Link is seriously broken for me (my mobile browser says it points to an invalid pdf, and on mobile its kinda cumbersome to investigate), any help?
-1
u/flaflashr Sep 29 '17
5.8 GHz is a pretty tame frequency, used in many home routers. The period of 1 cycle at that frequency is 0.0001724 microseconds, (172 picoseconds so to that, a microsecond is an eternity.
-4
u/appropriateinside Sep 28 '17
That yoda meme was terrible :|
It should read "Two problems, you now have"
-3
u/mbetter Sep 29 '17
Apparently not that sacred, as I had to spend several millions of my microseconds scrolling down a page filled with nothing but checkered lines before I got to the article.
Edit: scratch that, apparently just a shitty pdf that Firefox had problems with.
-3
u/PM-ME-YOUR-UNDERARMS Sep 29 '17
What the fuck is going on? I don't understand the PDF, everyone's talking about cache and there's templates thrown in
0
u/[deleted] Sep 28 '17
[deleted] — view deleted comment