Alex Rivera | Logout

When does code bloat start having a noticeable effect on performance?

Asked 2010-05-15T00:00:10.587
13

I am looking to make a hefty shift towards templates in one of my OpenGL projects, mainly for fun and the learning experience. I plan on watching the size of the executable carefully as I do this, to see just how much of the notorious bloat happens. Currently, the size of my Release build is around 580 KB when I favor speed and 440 KB when I favor size.

Yes, it's a tiny project, and in fact even if my executable bloats 10 x its size, it's still going to be 5 MB or so, which hardly seems large by today's standards... or is it? This brings me to my question. Is speed proportional to size, or are there leaps and plateaus at certain thresholds, thresholds which I should be aiming to stay below? (And if so, what are the thresholds specifically?)

Edit
Report

2 Answers

3

In my experience, code bloat and execution-time bloat go hand in hand, and it's all about how the software is designed, in particular, how the data structure is designed.

If one follows the approach that every mental concept becomes a class, if one follows the notification-style pattern where simply setting a property, or adding an item to a collection, can result in a hidden ripple effect of actions propogating throughout a large non-normalized data structure network in order to try to keep it consistent, then the result will be large source code and poor performance.

On the other hand, if one tries to minimize data structure and keep it normalized (as much as reasonably possible), if to a reasonable extent, inconsistency in the data structure can be tolerated and repaired on a loosely-coupled basis, and if code generation can be used so that the program is not processing information at run time that hardly ever changes and could have been handled prior to compiling, then source code will be smaller, easily developed, and efficient.

Here's a small example where a reasonably-designed program, through a series of steps, was reduced in size by a factor of four, and made faster by a factor of 40, by eliminating data structure and using code generation.

answered 2010-05-15T14:56:13.573
2

The size of your executable doesn't really matter. It is the size of the "active" code, the code which is actually executed frequently by the application, which matters. That is a lot harder to quantify, unfortunately. For a simple approximation, you could profile your application, take the procedures which account for 90% of the execution time, and add up their code sizes.

Most modern processors have 64KB or 128KB instruction caches, so it helps to keep the active code below this size. The next threshold would be L2 size, which can be a few megabytes.

answered 2010-05-15T00:16:52.667

Your Answer