Thursday, October 01, 2015

Software Performance–It’s Complicated

One of the things I don’t have near enough time to talk about in a one semester first programming course is performance. Arguably that is much more real computer science than just programming is but one has to prioritize. It doesn’t help that understanding the performance of code is a pretty complicated thing.

My recent post about finding different ways to solve a problem showed this in the comments where several of us went on a bit about performance. Even simple problems can have solutions with very different performances. There was a time when things seemed a lot less complicated.

In the early days some compilers produced assembly language code which was then often hand tuned by experts. One would be able to find some performance bottlenecks more easily that way. Compilers were relatively simple and “stupid” back then. Then we moved on to optimizing compilers. This changed things quite a bit. It really messed up some of the benchmark software that a lot of people used to understand how fast computer hardware was.

For example some test programs had null  loops – loops that iterated many times but did no real work. Before optimizing compilers the loop would run some number of times doing adds and compares and a time would result. An optimizing compiler would examine the code, realize it do no useful work, and just not include it in the running program. Huge performance improvement apparently.

Writing programs that tested the performance of the hardware became much harder. Of course that was a good thing for software development because these compilers allowed average programmers to write very high performing code. Programmers did not have to know as much about how the hardware worked.

That doesn’t mean that people can’t write slow code that the compiler can’t fix. Trust me it can be done. I’ve done it myself and my students are often amazingly good at writing bad code. So it is something we have to think about and teach to some degree. My students who advance to Advanced Placement Computer Science will get a lot more discussion on performance which will be good for them.

I believe one of the benefits of formal computer science education can be a deeper understanding of performance issues. Someone who understands how multi-dimension arrays are stored and processed (yes it can make a big difference) has an advantage over someone who doesn’t. And there are many more possible examples.

There is a lot going on behind the scenes in software. There is often a difference between writing software quickly and writing software that runs quickly. Understanding compilers, hardware, assembly and machine language, and other details about how things work can be very useful.

1 comment:

Unknown said...

That is so true, I'm a Software Engineer by profession, I see all the time many developers can code quickly but they cant write code with optimal performance.