title: Performance of C++ vs Virtual Machine languages in high frequency finance
body: <p>I thought the C/C++ vs C#/Java performance question was well trodden, meaning that I'd read enough evidence to suggest that the VM languages are not necessarily any slower than the "close-to-silicon" languages. Mostly because the JIT compiler can do optimizations that the statically compiled languages cannot.</p>
  
  <p>However, I recently received a CV from a guy who claims that Java-based high frequency trading  is always beaten by C++, and that he'd been in a situation where this was the case.</p>
  
  <p>A quick browse on job sites indeed shows that HFT applicants need knowledge of C++, and a look at <a href="http://www.wilmott.com" rel="noreferrer">Wilmott</a> forum shows all the practitioners talking about C++.</p>
  
  <p>Is there any particular reason why this is the case? I would have thought that with modern financial business being somewhat complex, a VM language with type safety, managed memory, and  a rich library would be preferred. Productivity is higher that way. Plus, JIT compilers are getting better and better. They can do optimizations as the program is running, so you'd think they's use that run-time info to beat the performance of the unmanaged program. </p>
  
  <p><strong>Perhaps these guys are writing the critical bits in C++ and and calling them from a managed environment (P/Invoke etc)? Is that possible?</strong></p>
  
  <p><strong>Finally, does anyone have experience with the central question in this, which is why in this domain unmanaged code is without doubt preferred over managed?</strong></p>
  
  <p>As far as I can tell, the HFT guys need to react as fast as possible to incoming market data, but this is not necessarily a <a href="http://en.wikipedia.org/wiki/Real-time_computing" rel="noreferrer">hard realtime</a> requirement. You're worse off if you're slow, that's for sure, but you don't need to guarantee a certain speed on each response, you just need a fast average.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Right, a couple of good answers thus far, but pretty general (well-trodden ground). Let me specify what kind of program HFT guys would be running.</p>
  
  <p>The main criterion is responsiveness. When an order hits the market, you want to be the first to be able to react to it. If you're late, someone else might take it before you, but each firm has a slightly different strategy, so you might be OK if one iteration is a bit slow.</p>
  
  <p>The program runs all day long, with almost no user intervention. Whatever function is handling each new piece of market data is run dozens (even hundreds) of times a second.</p>
  
  <p>These firms generally have no limit as to how expensive the hardware is.</p>