When not to optimize
Do not do clever optimizations that have no meaning. For example, people
who try to "optimize" the GUI interface. Hardwired constants, distributed
enabling, cute algorithms. The result is something that is hard to develop, difficult
to debug, and absolutely impossible to maintain.
Optimization is meaningless here. For more details, you might want to read
my essay on the only sensible way I've found to manage
dialog controls. I'll summarize the key idea here.
Why doesn't efficiency matter when you're updating menus or controls? Look
at the human factors. A mouse is held approximately 2 feet from the ear. Sound
travels at approximately 1100 ft/sec. This means that it takes approximately
2ms for the sound of the mouse click or keystroke to reach the ear. The neural
path from the fingertip to the brain of an adult is approximately 3 feet. Propagation
of nerve impulses is approximately 300 ft/sec, meaning the sensation of the mouse
click or keystroke takes approximately 10ms to reach the brain. Perceptual delay
in the brain can add between 50 and 250ms more.
Now, how many Pentium instructions can you execute in 2ms, 10ms, or 100ms?
In 2ms, on a 500MHz machine that's 1,000,000 clock cycles, so you can execute
a lot of instructions in that time. Even on a now-clunky 120MHz Pentium
there is no noticeable delay in handling the controls.
This did not stop Microsoft from totally violating the C++ object model on
message handlers; if you call CWnd::OnWhatever(...), instead of
actually calling DefWindowProc with the parameters you provide, they
re-use the parameters of the last message to call ::DefWindowProc. The
goal is to "reduce the size of the MFC runtime", as if a few hundred
instructions more in a massive DLL would matter! Even I can figure out how to
get CWnd::OnAnything to inline-expand to a call on DefWindowProc.