• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

FFS Microsoft

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #21
    Originally posted by bogeyman
    Do you like to obfuscate your code to show how clever you are?
    No. But I do use profiler to identify hot places that use most of CPU (that's how I ended up digging into Microsoft source). In such cases I am not shy to make code less maintainable if I can achieve serious speed up. Given number of people who use .NET framework and basic nature of Sort operation it should obviously be optimised for speed rather than programmer's convinience.

    For example I've got a perl script that would generate optimised code for some different situations, to maintain it I just need to maintain single piece of code plus script, the end code may not be readable but its extremely fast - this is what is required from any base library that actually ships without source in the first place.

    The most efficient variable swap would load such vars into registers and does a very quick swap, this is particularly good if along the execution path such variables will already have to be loaded into registers, so it means such swap can be done very nicely indeed with zero overhead. Of course this function should have been written in low level .NET assembly rather than C# - its sorting, it has got to be extremely fast not just algorithmically but also taking advantage of very good implementation. If I know it then people employed by Microsoft to do such a basic thing should know it 10 times better than me.
    Last edited by AtW; 1 August 2006, 15:39.

    Comment


      #22
      Can't you just get a girlfriend instead Alexei ?

      Comment


        #23
        Originally posted by AtW
        No. But I do use profiler to identify hot places that use most of CPU (that's how I ended up digging into Microsoft source). In such cases I am not shy to make code less maintainable if I can achieve serious speed up. Given number of people who use .NET framework and basic nature of Sort operation it should obviously be optimised for speed rather than programmer's convinience.

        For example I've got a perl script that would generate optimised code for some different situations, to maintain it I just need to maintain single piece of code plus script, the end code may not be readable but its extremely fast - this is what is required from any base library that actually ships without source in the first place.

        The most efficient variable swap would load such vars into registers and does a very quick swap, this is particularly good if along the execution path such variables will already have to be loaded into registers, so it means such swap can be done very nicely indeed with zero overhead. Of course this function should have been written in low level .NET assembly rather than C# - its sorting, it has got to be extremely fast not just algorithmically but also taking advantage of very good implementation.
        You really haven't understood what .NET is and what it isn't all about have you AtW?

        Comment


          #24
          Originally posted by AtW
          No. But I do use profiler to identify hot places that use most of CPU (that's how I ended up digging into Microsoft source). In such cases I am not shy to make code less maintainable if I can achieve serious speed up. Given number of people who use .NET framework and basic nature of Sort operation it should obviously be optimised for speed rather than programmer's convinience.

          For example I've got a perl script that would generate optimised code for some different situations, to maintain it I just need to maintain single piece of code plus script, the end code may not be readable but its extremely fast - this is what is required from any base library that actually ships without source in the first place.

          The most efficient variable swap would load such vars into registers and does a very quick swap, this is particularly good if along the execution path such variables will already have to be loaded into registers, so it means such swap can be done very nicely indeed with zero overhead. Of course this function should have been written in low level .NET assembly rather than C# - its sorting, it has got to be extremely fast not just algorithmically but also taking advantage of very good implementation. If I know it then people employed by Microsoft to do such a basic thing should know it 10 times better than me.

          Yes I understand your point. What I don't understand is why using an intermediate variable should cause such a hot spot given the alleged level of optimisation in the C# 'compiler'.

          I wonder why there isn't a swap x, y type of operator that the MSIL VM optimises using register transfers etc.

          So what did you do in the end?

          You've come right out the other side of the forest of irony and ended up in the desert of wrong.

          Comment


            #25
            Originally posted by DimPrawn
            You really haven't understood what .NET is and what it isn't all about have you AtW?
            Dude, look at the source code link I provided - note how their first choice is to call non-.NET native handoptimised search function called TrySZSort:

            00880 [MethodImplAttribute(MethodImplOptions.InternalCall )]
            00881 private static extern int TrySZSort(Array keys, Array items, int left, int right);

            Microsoft did indeed optimise well that function, however they spend zero time on other functions that suck terribly - and they call worse case scenario for no reason at all. Such a performance critical function could have been written in hand optimised .NET assembly (MSIL) to ensure peak performance.

            The variable swap was not the main issue - the main issue was that Array.Sort falls back wrongly to extremely slow version of sorting, see their source code to understand what it does. Inefficient variable swap is just a further sign that whoever programmed that code should work in Academical environment not real world because priority for the most basic sort code in very base library should be performance, not nice to read.

            Anyhow slow sorts that were #1 performance problem (in some scenarios) in SKA are now resolved, no thanks to Microsoft.

            Comment


              #26
              Originally posted by AtW
              The variable swap was not the main issue
              Cut the crap - how did you do the swap then?

              You've come right out the other side of the forest of irony and ended up in the desert of wrong.

              Comment


                #27
                Either using XOR method or

                a=b+a;
                b=a-b; /* now here b will get value of a */;
                a=a-b /*this will give a value of b */;

                or maybe I'm wrong

                Comment


                  #28
                  Originally posted by DimPrawn
                  Either using XOR method or

                  a=b+a;
                  b=a-b; /* now here b will get value of a */;
                  a=a-b /*this will give a value of b */;

                  or maybe I'm wrong
                  And in what way is that more efficient than using an intermediate var?

                  All the processor (in theory) needs to do is exchange three memory pointers (or two if it's a clever optimising compiler) - no arithmetic required.

                  Your solution requires 3 assignment operations and 2 arithmetic operations.
                  Last edited by bogeyman; 1 August 2006, 16:38. Reason: optimisation

                  You've come right out the other side of the forest of irony and ended up in the desert of wrong.

                  Comment


                    #29
                    Originally posted by DimPrawn
                    Either using XOR method or

                    a=b+a;
                    b=a-b; /* now here b will get value of a */;
                    a=a-b /*this will give a value of b */;

                    or maybe I'm wrong
                    But surely that could give overflow depending on the type

                    Comment


                      #30
                      Originally posted by ASB
                      But surely that could give overflow depending on the type
                      Correct.

                      Also no bloody use if the variables are references (pointers in old money) to objects like strings etc. Atw please correct me if I'm wrong.

                      You've come right out the other side of the forest of irony and ended up in the desert of wrong.

                      Comment

                      Working...
                      X