Optimization, part 2



All timestamps are based on your local time of:

Posted by: stak
Posted on: 2008-04-20 12:27:09

So this post isn't so much about how to go about optimizing code, but rather why it's important to optimize code, even if it doesn't seem like performance matters. The short version is: performance always matters. Sooner or later, any significant piece of code turns into a platform for other code, and basically turns into a library. As a library, it gets used a lot more than it did before, and any performance problems present will get multiplied.

I think that in an ideal world, direct interaction with computers would be pretty limited. They would just sort of exist in the background and do what we needed them to do, without having us to ask them directly. Instead of having to go online and search for flights for your next vacation and find the cheapest fare, you'd just block off two weeks on your calendar and label them "vacation". Some computer somewhere would look at this and go find you some vacation packages you'd be interested in, and maybe even just pick one based on your preferences. However, in order for this to work, the "searching for flights" part of travel websites/databases would have to be turned into a library that can be invoked programmatically lots of times. And that's just for vacations. There might be hundreds of things you do every day that the "background computers" would do travel searches for, just in case you needed it.

As of the last time I checked, searching for flights is, by internet standards, horrendously slow. You actually have to stare at a "please wait" page while they do the search. If it takes 10 seconds for a beefed-up server to search the database for matching flights, there's almost no way that those background computers would be able to finish the millions of travel searches they'd need to do. Not in the current state, anyway. This is where optimization is essential. By bringing down the time required to conduct a flight search, that search can be invoked many more times, enabling it to be used as a building block for something better.

There are probably lots of flaws in the travel example above, but I think the general point stands. Just about any standalone app that requires user interaction can be turned into a library to be invoked by background computers. But in order to do so, that code should be able to complete its task within a reasonable period of time. Of course, that period of time depends on the task, but the faster it can be done, the more useful the code will be as a component of a much larger system.

[ Add a new comment ]

 
 
(c) Kartikaya Gupta, 2004-2022. User comments owned by their respective posters. All rights reserved.
You are accessing this website via IPv4. Consider upgrading to IPv6!