开发者

Best way to learn how to write latency-critical, fast C++/Java/C# code? [closed]

开发者 https://www.devze.com 2023-02-07 10:38 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_JS百科 Closed 12 years ago.

Could anyone give me some pointers as to the best way in which to learn how to do very low latency programming? I have many programming books but I've never seen one which focused (or helped) on writing extremely fast code. Or are books not the best way forward?

Some advice from an expert would be really appreciated!

EDIT: I think I'm referring more to CPU/Memory bound.


[C++ programmer]:

Ultra-low-latency programming is hard. Much harder than people suspect when they first start down the path. There are some techniques and "tricks" you can employ. Like IO Completion ports, multi core utilization, highly optimized synchronization techniques, shared memory. The list goes on forever. (edit) It's not as simple as "code-profile-refactor-repeat" because you can write excellent code that is robust and fast, but will never be truly ultra-low latency code.

Unfortunately there is no one single resource I know of that will show you how it's done. Programmers specializing in (and good at) ultra low-latency code are among the best in the business and the most experienced. And with good reason. Because if there is a silver bullet solution to becoming a good low-latency programmer, it is simply this: you have to know a lot about everything. And that knowledge is not easy to come by. It takes years (decades?) of experience and constant study.

As far as the study itself is concerned, here's a few books I found useful or especially insightful for one reason or another:

  • MSDN Libraries
  • Art Of Computer Programming
  • Hacker's Delight
  • Unix Network Programming: Vol 1
  • Computer Architechture
  • Tech journals on the ACM


My advice would be to learn how C++/Java/C# works and get a general idea of how it translates into machine level instructions. Some operations are more expensive that others. A little code snippet in a high-level language translates into a whole bunch of machine instructions (often more than you would think.)

Also, be sure to learn the various data structures, what they are good for, and their performance characteristics for various problem sizes. Choosing the correct data structure for the problem can do wonders for execution speed.


Start by learning assembly. Then if you're going to work in Java or .NET learn their interpreted bytecode. Once you've gotten that far you need to understand the language you are working in, and the compiler you're working on. Keep on that path and you'll collect bits of knowledge like how with both VC++ and GCC ternary operators (?:) result in creation of temporary values whereas an equivalent if statement will not.

Then after about 10 years you'll be able to write pretty good low-latency code.

Unfortunately there is no quick way to learn this.

Good books to learn about C++: Effective C++ More Effective C++ Exceptional C++

0

精彩评论

暂无评论...
验证码 换一张
取 消