Re: /CLR Compilation: 125x slower when calling virtual function fr

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Kapil Khosla [MSFT] (kkhosla_at_online.microsoft.com)
Date: 01/25/05


Date: Mon, 24 Jan 2005 21:36:25 -0800


> And as Jochen well said, unfortunately this doesn't solve the problems of
> current projects...
> Any chances of a service pack to fix such issue on 2003 or it's a big
> change and will only be available on whidbey?

Sure. I think I can give you a workaround for it in everett.

>From your code

#include <time.h>
#include <stdio.h>
/*******Note the pragma unmanaged *******/
#pragma unmanaged
class MyTest1
{
 private:
  int s_i;
  virtual void Test1(int i)
  {
    s_i += i;
  }

 public:
  void MakeTest()
  {
 clock_t start, finish;
    double duration;

 start = clock();
    for(int i = 0; i< 10000000; i++)
    {
      Test1(i);
    }
 //EndTimeMeasure();
  finish = clock();
     duration = (double)(finish - start) / (CLOCKS_PER_SEC);
  printf( "%2.1f seconds\n", duration );

  }
};

int main()
{
 MyTest1 obj;
 obj.MakeTest();
}

When you compiled your native class with /clr, it causes what is called
double thunking. A call is made from a managed call site to a mangaged
function definition via a native vtable.

Yes, that is right. The vtable is native in this case so there is
performance penalty when you make a transition from managed - native and
native - managed. When I applied #pragma unmanaged over the function
definition, I reduce the thunking from native to managed and thus saved the
performance penalty. On my everett compiler this code took .4 seconds vs
13.5 seconds if I dont use #pragma unmanaged.

Please let me know if this fixes your problem.

Thanks, Kapil

"Gustavo L. Fabro" <gustavo_fabro%remove_this%@hotmail.com> wrote in message
news:35l7rtF4ojph5U1@individual.net...
>> Thanks for your reply. I have verified that this is an issue with the
>> Everett
>> compiler but this is fixed in beta1 whidbey. You can download beta1 from
>> msdn.microsoft.com/visualc.
>> Thanks,
>> Kapil
>
>
> Thanks for the comments. I've downloaded whidbey beta 1 (Visual C++ 2005
> Express Edition Beta) and run the same tests. After a few teaks to compile
> the test properly, things indeed worked much better:
>
> Timings:
>
> Visual C++ 2005 Beta 1
> ----------------------------
> With /CLR : 495
> Without /CLR: 382
>
> Visual C++ .NET 2003
> ----------------------------
> With /CLR: 18879
> Without /CLR: 151
>
>
> Borland Builder 5.0 (for comparison)
> ----------------------------
> Builder: 420
>
> Any clues as to when will the final version of VS 2005 be available?
>
> And as Jochen well said, unfortunately this doesn't solve the problems of
> current projects...
> Any chances of a service pack to fix such issue on 2003 or it's a big
> change and will only be available on whidbey?
>
> Thanks
>
> Gustavo Fabro
> gustavo_fabro%removethis%@hotmail.com
>
>



Relevant Pages

  • Re: /CLR Compilation: 125x slower when calling virtual function fr
    ... > Any chances of a service pack to fix such issue on 2003 or it's a big ... On my everett compiler this code took .4 seconds vs ...
    (microsoft.public.dotnet.languages.vc)
  • Re: CUT AND RUN?
    ... Chances of that happening in 5 years with Republican incompetence - ... Japan was, and is, completely different than the chaotic Iraq nation. ... armor, scrimps on armored vehicles, scrimps on VA funding, scrimps on ... We should fix what we broke. ...
    (alt.politics.bush)
  • Re: How do you forth experts drop a break_point ?
    ... Say that I believe the problem is at step 2417 of a do loop. ... rummage through it enough to find this error and fix it, chances are ... There's a strong temptation not to do that for commercial code because ... Much more pleasant to think that one last patch will fix ...
    (comp.lang.forth)
  • Re: CUT AND RUN?
    ... Chances with a presence comparable to that in Japan after WWII ... Japan was, and is, completely different than the chaotic Iraq ... armor, scrimps on armored vehicles, scrimps on VA funding, scrimps ... We should fix what we broke. ...
    (alt.politics.bush)
  • Re: VS.NET file locking problem : Totally screwed
    ... I'm sure MS could fix this particular problem right now if they ... > would only release a service pack for the VS IDE. ... configurations (a normal and a pro version of the product, ... includes all plugins while the normal version only has a subset of them). ...
    (microsoft.public.dotnet.general)