optimizing c++ code (on win32 platform), all the techniques you know?

T

Tzu-Chien Chiu

Hi,

"What methods do you ever use to optimize the programs?"

We're developing a graphics chip emulator in C++, but it's very slow
for big scenes. Even though this is a cross-platform software, I only
want to optimize it on the Win32 (Windows 2000/XP) platform.

I've tried the following method to optimize it:

* Boost.Pool - a fast memory allocation algoritm, fixed-size chunks.
<http://www.boost.org/libs/pool/doc/index.html>

* Whole Program Optimization with Visual C++ .NET
<http://www.codeproject.com/tips/gloption.asp>
I almost turn on every possbile Visual C++ options to optimize the
speed.

* inline every possbile function


Not tried yet:

* Improving Runtime Performance with the Smooth Working Set Tool
<http://msdn.microsoft.com/msdnmag/issues/1000/bugslayer/default.aspx>
I don't think it will help much, because our program is about 500KB.
Or not?

* Recompile the CRT with _fastcall calling convetion

* Link single-thread CRT instead of multi-thread CRT
We don't use many CRT functions.

* Distributed Computing
<http://www-unix.mcs.anl.gov/mpi/>
Uh, not feasible. I am looking for "fast" approches, like a compiler
option, etc.
 
D

David White

Tzu-Chien Chiu said:
Hi,

"What methods do you ever use to optimize the programs?"


We're developing a graphics chip emulator in C++, but it's very slow
for big scenes. Even though this is a cross-platform software, I only
want to optimize it on the Win32 (Windows 2000/XP) platform.

This question isn't suitable for c.l.c++, at least where a specific
implementation is concerned.
I've tried the following method to optimize it:

* Boost.Pool - a fast memory allocation algoritm, fixed-size chunks.
<http://www.boost.org/libs/pool/doc/index.html>

Or ditch memory allocation altogether, at least in the most critical parts
of your code. Many firmware engineers manage to design their systems to
_never_ do a memory allocation except during initialization, since a
recurring memory leak, even a small one, means death for an embedded system.
* Whole Program Optimization with Visual C++ .NET
<http://www.codeproject.com/tips/gloption.asp>
I almost turn on every possbile Visual C++ options to optimize the
speed.

It goes without saying to generate the fastest code possible, but this is
off-topic here.
* inline every possbile function

Well, every one that could possibly have a significant effect, which would
be the ones that a) do or might return quickly, and b) are called very
often. There's no point in spending hours moving functions to header files
if a cursory analysis of the program shows that doing so will make an
insiginificant difference.
Not tried yet:

* Improving Runtime Performance with the Smooth Working Set Tool
<http://msdn.microsoft.com/msdnmag/issues/1000/bugslayer/default.aspx>
I don't think it will help much, because our program is about 500KB.
Or not?

* Recompile the CRT with _fastcall calling convetion

* Link single-thread CRT instead of multi-thread CRT
We don't use many CRT functions.

* Distributed Computing
<http://www-unix.mcs.anl.gov/mpi/>
Uh, not feasible. I am looking for "fast" approches, like a compiler
option, etc.

I don't see anything relevant to c.l.c++ in all this.

Have you thought of redesigning your algorithms so they work more
efficiently? That's more likely to make a bigger difference than squeezing
out 10% better performance by quick or mechanical means such as compiler
options or moving code about.

DW
 
A

Alex Blekhman

Tzu-Chien Chiu said:
"What methods do you ever use to optimize the programs?"

We're developing a graphics chip emulator in C++, but it's very slow
for big scenes. Even though this is a cross-platform software, I only
want to optimize it on the Win32 (Windows 2000/XP) platform.

Actually, the most efficient method is detect your bottleneck first. Before
you know exactly where most of time is wasted, any speculations about
optimization are pointless. It can be that your program spend 1% of time in
allocations and 90% of time in buffer transfers, so even if the miracle will
happen and you'll succeed to accelerate allocations twice, then still you'll
gain only 0.5% in overall time. And you can spend hours and days by
optimizing not relevant parts of the program with negligible effect. I think
you got the idea. Here's the article for general reading:
"Optimization: Your Worst Enemy"
By Joseph M. Newcomer
<http://www.codeproject.com/tips/optimizationenemy.asp>
 
J

Jussi Jumppanen

Tzu-Chien Chiu said:
"What methods do you ever use to optimize the programs?"

We're developing a graphics chip emulator in C++, but it's very slow
for big scenes. Even though this is a cross-platform software, I only
want to optimize it on the Win32 (Windows 2000/XP) platform.

If you application seems very slow on todays super fast GHz PC's, that
to me that suggests the application it is doing an awful lot of CPU
intensive stuff.

Have you profiled your application to check that the appliction is not
wasting time on a badly code algorithm or flow structure? Does you
machine have lots of spare RAM? RAM always helps speed up memory
hunger applications.

If you do have an optimal algorithm then your applicaiton is just CPU
intensive and I would be suprised if the any amount of optimazation
would greatly improve the speed.

Jussi Jumppanen
Author of: Zeus for Windows, Win32 (Brief, Emacs, etc) FTP Text Editor
"The C/C++, Java, HTML, FTP, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com
 
L

llewelly

Jussi Jumppanen said:
If you application seems very slow on todays super fast GHz PC's, that
to me that suggests the application it is doing an awful lot of CPU
intensive stuff.
[snip]

That is usually wrong. I/O speeds are hundres of thousands of times
slower than cpu speeds. The speed of a system is usually most
strongly dependent on the speed of its slowest parts. Many more
programs are I/O bound, and can be very slow even when only using
1 or 2% of cpu.

Memory-bound and system-call bound progams are also more common than
cpu-bound progams.
 
O

Oliver Wesnigk

Have you try V-Tune, to find the bottleneck or the Intel-Compiler
sometimes it's helpfull

Oliver Wesnigk
 
C

cody

* Boost.Pool - a fast memory allocation algoritm, fixed-size chunks.

when you use it wrong, you need much more memory than you actually need.
* Whole Program Optimization with Visual C++ .NET
<http://www.codeproject.com/tips/gloption.asp>
I almost turn on every possbile Visual C++ options to optimize the
speed.

Good idea, but some options can under certain circumstances create
errors in your executable
* inline every possbile function

That is very stupid. inlining very small functions that are called in
loops can be a good idea, but inlining every function in the program
is just stupid because it bloats the code which then makes code
caching very unefficient.
* Recompile the CRT with _fastcall calling convetion

This can lead to errors too. be very careful.

As the foreposter said, before you start wasting your time with
useless things like spending 90% time on things that comsumes 0.01% of
performance, detect what certain loops are slow, instead of
bit-fiddling rethink your algorithms.
 
B

Brian Inglis

Tzu-Chien Chiu said:
"What methods do you ever use to optimize the programs?"

Read any book by Jon Bentley or containing the words "Programming
Pearls".

Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
 

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top