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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tzu-Chien Chiu

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

    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.go v/mpi/>
    Uh, not feasible. I am looking for "fast" approches, like a compiler
    option, etc.

    --
    Tzu-Chien Chiu
    XGI Technology, Inc - Extreme Graphics Innovaion
  • David White

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

    Tzu-Chien Chiu <tzuchien_chiu@ xgitech.com> wrote in message
    news:03-09-070@comp.compil ers...[color=blue]
    > 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.[/color]

    This question isn't suitable for c.l.c++, at least where a specific
    implementation is concerned.
    [color=blue]
    > 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>[/color]

    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.
    [color=blue]
    >
    > * 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.[/color]

    It goes without saying to generate the fastest code possible, but this is
    off-topic here.
    [color=blue]
    >
    > * inline every possbile function[/color]

    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.
    [color=blue]
    >
    > 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.go v/mpi/>
    > Uh, not feasible. I am looking for "fast" approches, like a compiler
    > option, etc.[/color]

    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



    Comment

    • Alex Blekhman

      #3
      Re: optimizing c++ code (on win32 platform), all the techniquesyou know?

      "Tzu-Chien Chiu" <tzuchien_chiu@ xgitech.com> wrote in message
      [color=blue]
      > "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.[/color]

      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:
      "Optimizati on: Your Worst Enemy"
      By Joseph M. Newcomer
      <http://www.codeproject .com/tips/optimizationene my.asp>

      Comment

      • Jussi Jumppanen

        #4
        Re: optimizing c++ code (on win32 platform)

        Tzu-Chien Chiu wrote:
        [color=blue]
        > "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.[/color]

        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

        Comment

        • llewelly@xmission.com

          #5
          Re: optimizing c++ code (on win32 platform)

          Jussi Jumppanen <jussij@zeusedi t.com> writes:
          [color=blue]
          > Tzu-Chien Chiu wrote:
          >[color=green]
          > > "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.[/color]
          >
          > 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.[/color]
          [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.

          Comment

          • cody

            #6
            Re: optimizing c++ code (on win32 platform), all the techniquesyou know?

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

            when you use it wrong, you need much more memory than you actually need.
            [color=blue]
            > * 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.[/color]

            Good idea, but some options can under certain circumstances create
            errors in your executable
            [color=blue]
            > * inline every possbile function[/color]

            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.
            [color=blue]
            > * Recompile the CRT with _fastcall calling convetion[/color]

            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.

            --
            cody

            Freeware Tools, Games and Humour

            Comment

            • Oliver Wesnigk

              #7
              Re: optimizing c++ code (on win32 platform)

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

              Oliver Wesnigk

              "Tzu-Chien Chiu" <tzuchien_chiu@ xgitech.com> wrote in message
              [color=blue]
              > "What methods do you ever use to optimize the programs?"[/color]

              Comment

              • Jeff Kenton

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


                Tzu-Chien Chiu wrote:[color=blue]
                > "What methods do you ever use to optimize the programs?"[/color]

                Don't optimize your programs before you design them.

                --
                = Jeff Kenton Consulting and software development =
                = http://home.comcast.net/~jeffrey.kenton =

                Comment

                • WW

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

                  Tzu-Chien Chiu wrote:[color=blue]
                  >
                  > "What methods do you ever use to optimize the programs?"[/color]



                  Short URL: http://tinyurl.com/ncpc

                  --
                  WW aka Attila

                  Comment

                  • Brian Inglis

                    #10
                    Re: optimizing c++ code (on win32 platform)

                    Tzu-Chien Chiu wrote:
                    [color=blue]
                    > "What methods do you ever use to optimize the programs?"[/color]

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

                    Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
                    --
                    Brian.Inglis@CS i.com (Brian dot Inglis at SystematicSw dot ab dot ca)
                    fake address use address above to reply

                    Comment

                    Working...