Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm currently in a role where I dont get to write any C++ or Java. However, the role is good because provides me with exposure to the business side (i'm interested in finance).

Eventually I would like to get into high frequency trading infrastructure. Therefore, outside of work hours i'd like to maximise the knowledge I can gain about high performance Java and C++. I already have the Java Performance Tuning book, which is ok but not impressive.

Can people recommend anymore latency blogs/books/websites for learning about making C++/C/Java or even Unix very fast?

Or perhaps making the network parts of the OS (if re-writing Unix components) faster?

EDIT: Or perhaps we could make this THE thread for advice on writing fast code

share|improve this question
2  
This is a question, not a thread; threads are on forums which this is not. Also book requests are off topic. – Jimmy Hoffa Nov 22 '12 at 16:16

closed as off topic by gnat, maple_shaft Nov 22 '12 at 16:45

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

4 Answers

up vote 1 down vote accepted

On the Java side look at the disruptor + Doug Lea's and Brian Goetz's 2 books on concurrent programming.

share|improve this answer

I'm pretty sure in industry people don't start out writing "fast" code, they start out writing correct and well designed code. Start with something that works. Then measure, via performance tests and benchmarking. Then if performance is good enough stop (and I would wager that if the design is good in java or c++ then you're done here). Otherwise use profiling tools (like JProfiler for java) to look for bottlenecks. Then look for improvements. Over time the code gets "fast".

Aside from that you should probably understand how to write systems that scale horizontally.

share|improve this answer
3  
While I agree to some extent, if performance requirements are stringent enough you sometimes need to design upfront for performance or you'll paint yourself into a corner and need to redesign large portions of your application. Micro-optimization should not be done without profiling, but design-level optimization sometimes needs to be done up front. – dsimcha Nov 24 '11 at 1:20
Designing for horizontal scaling is an example of this (which I did mention). But I do agree with you, there are certainly design level decisions that hugely affect performance. I just don't think they have a lot to do with c++ or java. For example using mongodb instead of mysql affects performance at scale but has little to do with programming languages. – Kevin Nov 24 '11 at 4:02

I have worked in several organizations completely obsessed with performance. Design intended to be legible, clear, easy to maintain tends to destroy code intended to be fast.

Write the right code, then profile it to be fast.

Here is an article that is helpful, just don't drink too much kool-aid.

What every programmer should know about memory, Part 1

share|improve this answer

I've to agree with some of your comments, doing optimization in an early stage is not always the best, but that usually depends on the problem you're intending to solve, as the poster mentioned he will create a financial application intended to manage large scale customers and data, then he will need to address the performance issues upfront or he could get fired as soon as the software is released.

To answer the original question, try to create the code, that needs to boost performance, it as simple as possible, even if that means to copy'n paste some code into a large function, sometimes the OO creates little issues in your software that you only noticed when it's running on production. From my experience, bare in mind that one of the greatest killers of the performance is the following instruction:

String a = b + c;

If you're creating a fast performance system, then you need to be aware of this simple, but massive, error and use buffers to avoid memory reallocation. Let me mention an example of this, I'm architect of a solution, in one customer we had a performance problem processing a huge set of data, we did a profile and everything looks great, except for some "native" calls, that we just skipped, after several hours of hard work we decided to tackle does "unrelated" problems, just because we dont have anything left to do on our code, in the top of the list was "StringBuffer.append", then we started to look around in our code to see where the stringbuffer is been used that caused that massive problems and found the following code (which was allover the application)

CacheSystem.add(PREFIX + KEY, obj);

The PREFIX + KEY was the problem... we changed our cache strategy to save a hashtable and use the "key" to access the inner elements, and boom!, that gained 50% of the performance, a method that took 300ms (the first caller of the whole process) changed to 30ms after this change (off course, we'd to change this in several spots).

As someone else mentioned earlier, a system designed to be fast is not as easy to maintain as other kind of software, but it's a trade-off you need to do.

share|improve this answer
2  
-1 for suggesting copy'n'paste and that procedural for a large complex system is a better approach. Your answer mentions you had to fix that one issue in several spots, and due to your copy-pasta approach you really don't know that you got them all, especially if you're practicing procedural coding because it's easy to not find something like that inside methods that are hundreds of lines long.. – Jimmy Hoffa Nov 22 '12 at 16:22
I'm not suggesting to copy logic, but sometimes avoiding some reuse is better than creating a full class to support simple code that will perform better as copy'n paste... if you have a language like C or C++ where you can use the "inline" it would be better, if not... do what works best. – Cross Nov 23 '12 at 16:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.