C# optimization trick

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marty

    #1

    C# optimization trick

    Hi,

    I've read that the if/else statement, or get/set accessor, can be
    compiled inline by the C# compiler if they are small enough.

    Have you seen any documentation that 'summarized' all thoses
    optimizations tricks? I would like to be aware of all tips and trick
    that should be used as good programming habits that make any software
    coding optimized. I remember that in VB6 there was a lot of
    optimization tips.

    So my question does not concern solving bottleneck inside an algorithm,
    but tricks related on the language itself.

    If you have any idea, that would be very appreciated, thanks!

    Regards,
    Marty
  • Peter Bromberg [C# MVP]

    #2
    RE: C# optimization trick

    Check out some of the Patterns and Practices whitepapers. Here's a good one:

    http://msdn.microsoft.com/practices/...l/scalenet.asp

    Peter
    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "Marty" wrote:
    [color=blue]
    > Hi,
    >
    > I've read that the if/else statement, or get/set accessor, can be
    > compiled inline by the C# compiler if they are small enough.
    >
    > Have you seen any documentation that 'summarized' all thoses
    > optimizations tricks? I would like to be aware of all tips and trick
    > that should be used as good programming habits that make any software
    > coding optimized. I remember that in VB6 there was a lot of
    > optimization tips.
    >
    > So my question does not concern solving bottleneck inside an algorithm,
    > but tricks related on the language itself.
    >
    > If you have any idea, that would be very appreciated, thanks!
    >
    > Regards,
    > Marty
    >[/color]

    Comment

    • Marty

      #3
      Re: C# optimization trick

      Hi Peter,

      I had a look and it seem to have a lot of content, I'll read it all.

      Thank you very much :)
      Marty

      Peter Bromberg [C# MVP] wrote:[color=blue]
      > Check out some of the Patterns and Practices whitepapers. Here's a good one:
      >
      > http://msdn.microsoft.com/practices/...l/scalenet.asp
      >
      > Peter[/color]

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: C# optimization trick

        Marty <xmarty99@hotma il.com> wrote:[color=blue]
        > I've read that the if/else statement, or get/set accessor, can be
        > compiled inline by the C# compiler if they are small enough.[/color]

        No, they get inlined by the JIT - that's slightly different. In
        particular, it's not a C# trick, it would happen in VB.NET too, for
        instance.
        [color=blue]
        > Have you seen any documentation that 'summarized' all thoses
        > optimizations tricks? I would like to be aware of all tips and trick
        > that should be used as good programming habits that make any software
        > coding optimized. I remember that in VB6 there was a lot of
        > optimization tips.
        >
        > So my question does not concern solving bottleneck inside an algorithm,
        > but tricks related on the language itself.
        >
        > If you have any idea, that would be very appreciated, thanks![/color]

        I think it's more a case of *platform* "tricks" than language tricks.
        For instance, you really ought to (and probably already do) know about
        StringBuilder:
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.


        Is that the kind of thing you're after? I'll think about some more.

        --
        Jon Skeet - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too

        Comment

        • Nick Hounsome

          #5
          Re: C# optimization trick

          "Marty" <xmarty99@hotma il.com> wrote in message
          news:J0Sxf.5460 9$km.7484@edtnp s89...[color=blue]
          > Hi,
          >
          > I've read that the if/else statement, or get/set accessor, can be compiled
          > inline by the C# compiler if they are small enough.
          >
          > Have you seen any documentation that 'summarized' all thoses optimizations
          > tricks? I would like to be aware of all tips and trick that should be
          > used as good programming habits that make any software coding optimized.
          > I remember that in VB6 there was a lot of optimization tips.[/color]

          1. It's the JIT compiler that does it at runtime from the IL bytes not the
          C# compiler.
          2. How does it help you to optimize your accessors? Surely they already
          contain as much code as they need to and no more.
          3. As a general guidline you should use methods rather than properties where
          a lot of work is involved. It's not a rule but people will assume that
          property access is always efficient.


          Comment

          • Marty

            #6
            Re: C# optimization trick

            Hi Jon,

            Thanks for the correction about C# compiler and JIT. Yes, this is the
            kind of optimization trick I am looking for.

            Regards
            Marty

            Jon Skeet [C# MVP] wrote:[color=blue]
            > Marty <xmarty99@hotma il.com> wrote:
            >[color=green]
            >>I've read that the if/else statement, or get/set accessor, can be
            >>compiled inline by the C# compiler if they are small enough.[/color]
            >
            >
            > No, they get inlined by the JIT - that's slightly different. In
            > particular, it's not a C# trick, it would happen in VB.NET too, for
            > instance.
            >
            >[color=green]
            >>Have you seen any documentation that 'summarized' all thoses
            >>optimizatio ns tricks? I would like to be aware of all tips and trick
            >>that should be used as good programming habits that make any software
            >>coding optimized. I remember that in VB6 there was a lot of
            >>optimizatio n tips.
            >>
            >>So my question does not concern solving bottleneck inside an algorithm,
            >>but tricks related on the language itself.
            >>
            >>If you have any idea, that would be very appreciated, thanks![/color]
            >
            >
            > I think it's more a case of *platform* "tricks" than language tricks.
            > For instance, you really ought to (and probably already do) know about
            > StringBuilder:
            > http://www.pobox.com/~skeet/csharp/stringbuilder.html
            >
            > Is that the kind of thing you're after? I'll think about some more.
            >[/color]

            Comment

            Working...