interop & performance

L

Lloyd Dupont

I have an application which use has a DLL with 100+ (auto-generated) Managed
C++ wrapper around some native API.

Compare to a purely version my application has some performance issue and I
just realized it is probably due to the security check which happen just
before each of the (numerous) call into this native API.

Now I know that, perhaps, I could tag my MC++ wrapper with
<SuppressUnmanagedCodeSecurityAttribute>

But I wonder if there is not an other call I could place in the Main()
function (such as Permission.Demand() or stuff like that) which will achieve
the same result?

After all my code this is for a desktop application with as much right as
the user.
 
G

Guest

I have an application which use has a DLL with 100+ (auto-generated) Managed
C++ wrapper around some native API.

Compare to a purely version my application has some performance issue and I
just realized it is probably due to the security check which happen just
before each of the (numerous) call into this native API.

I don't know how much impact the security configuration has, but
transitioning between managed and unmanaged context takes time too, as well
as marshalling parameters back and forth.
If you have to do this lots of times per second, this will have a
significant impact.
If that is your problem, there is very little you can do about that while
keeping your design as it is now.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
L

Lloyd Dupont

It could only be security.

No parameter marshalling happen, as I am using C and Pointers (not array!)

1 million method call (which just increment an int by 1) takes 94ms in pure
native or .NET
but 700ms when I use a mix of both.
I suspect the security stack walk to be the culprit...
 
D

Dominick Baier

SUCS is indeed a significant performance improvement for unmanmaged calls.
Not sure if it applies to your scenario - but give it a try.

Just be aware of the implications - this means that a partially trusted callers
can use your wrapper to call Win32 without having unmanaged code access.

dominick
 
L

Lloyd Dupont

Well I don't have any plugin API so there is no problem....

But my question was: is there a replacement of [SUCS] ?
like using a demand or similar stuff?
 
D

Dominick Baier

Ah ok - adding SUCS will not improve performance - replacing Assert with
SUCS is usually a perf improvement.


Well I don't have any plugin API so there is no problem....

But my question was: is there a replacement of [SUCS] ? like using a
demand or similar stuff?

SUCS is indeed a significant performance improvement for unmanmaged
calls. Not sure if it applies to your scenario - but give it a try.

Just be aware of the implications - this means that a partially
trusted callers can use your wrapper to call Win32 without having
unmanaged code access.

dominick
 
L

Lloyd Dupont

This one!

CodeAccessPermission.Assert()

Anyway, it's not as good as
SupressUnmanagedCodeSecurityAttribute

Dominick Baier said:
Ah ok - adding SUCS will not improve performance - replacing Assert with
SUCS is usually a perf improvement.


Well I don't have any plugin API so there is no problem....

But my question was: is there a replacement of [SUCS] ? like using a
demand or similar stuff?

SUCS is indeed a significant performance improvement for unmanmaged
calls. Not sure if it applies to your scenario - but give it a try.

Just be aware of the implications - this means that a partially
trusted callers can use your wrapper to call Win32 without having
unmanaged code access.

dominick

I have an application which use has a DLL with 100+ (auto-generated)
Managed C++ wrapper around some native API.

Compare to a purely version my application has some performance
issue and I just realized it is probably due to the security check
which happen just before each of the (numerous) call into this
native API.

Now I know that, perhaps, I could tag my MC++ wrapper with
<SuppressUnmanagedCodeSecurityAttribute>

But I wonder if there is not an other call I could place in the
Main() function (such as Permission.Demand() or stuff like that)
which will achieve the same result?

After all my code this is for a desktop application with as much
right as the user.
 
D

Dominick Baier

:) that's what i said...

dominick
This one!

CodeAccessPermission.Assert()

Anyway, it's not as good as
SupressUnmanagedCodeSecurityAttribute
Ah ok - adding SUCS will not improve performance - replacing Assert
with SUCS is usually a perf improvement.
Well I don't have any plugin API so there is no problem....

But my question was: is there a replacement of [SUCS] ? like using a
demand or similar stuff?

"Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com>
wrote in message

SUCS is indeed a significant performance improvement for unmanmaged
calls. Not sure if it applies to your scenario - but give it a try.

Just be aware of the implications - this means that a partially
trusted callers can use your wrapper to call Win32 without having
unmanaged code access.

dominick

I have an application which use has a DLL with 100+
(auto-generated) Managed C++ wrapper around some native API.

Compare to a purely version my application has some performance
issue and I just realized it is probably due to the security check
which happen just before each of the (numerous) call into this
native API.

Now I know that, perhaps, I could tag my MC++ wrapper with
<SuppressUnmanagedCodeSecurityAttribute>

But I wonder if there is not an other call I could place in the
Main() function (such as Permission.Demand() or stuff like that)
which will achieve the same result?

After all my code this is for a desktop application with as much
right as the user.
 
L

Lloyd Dupont

Ho... this Assert?

I didn't know about it!
It's why I was asking!

I though you were talking about System.Diagnostic.Assert
I though it was non sensical!


I should have know better!
Someone who thinks SUCS is an understandable acronym is likely to have a
second meaning! ;-)


Dominick Baier said:
:) that's what i said...

dominick
This one!

CodeAccessPermission.Assert()

Anyway, it's not as good as
SupressUnmanagedCodeSecurityAttribute
Ah ok - adding SUCS will not improve performance - replacing Assert
with SUCS is usually a perf improvement.

Well I don't have any plugin API so there is no problem....

But my question was: is there a replacement of [SUCS] ? like using a
demand or similar stuff?

"Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com>
wrote in message

SUCS is indeed a significant performance improvement for unmanmaged
calls. Not sure if it applies to your scenario - but give it a try.

Just be aware of the implications - this means that a partially
trusted callers can use your wrapper to call Win32 without having
unmanaged code access.

dominick

I have an application which use has a DLL with 100+
(auto-generated) Managed C++ wrapper around some native API.

Compare to a purely version my application has some performance
issue and I just realized it is probably due to the security check
which happen just before each of the (numerous) call into this
native API.

Now I know that, perhaps, I could tag my MC++ wrapper with
<SuppressUnmanagedCodeSecurityAttribute>

But I wonder if there is not an other call I could place in the
Main() function (such as Permission.Demand() or stuff like that)
which will achieve the same result?

After all my code this is for a desktop application with as much
right as the user.
 
D

Dominick Baier

:))
Ho... this Assert?

I didn't know about it!
It's why I was asking!
I though you were talking about System.Diagnostic.Assert I though it
was non sensical!

I should have know better!
Someone who thinks SUCS is an understandable acronym is likely to have
a
second meaning! ;-)
:) that's what i said...

dominick
This one!

CodeAccessPermission.Assert()

Anyway, it's not as good as
SupressUnmanagedCodeSecurityAttribute
"Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com>
wrote
in message Ah ok - adding SUCS will not improve performance - replacing Assert
with SUCS is usually a perf improvement.

Well I don't have any plugin API so there is no problem....

But my question was: is there a replacement of [SUCS] ? like using
a demand or similar stuff?

"Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com>
wrote in message

SUCS is indeed a significant performance improvement for
unmanmaged calls. Not sure if it applies to your scenario - but
give it a try.

Just be aware of the implications - this means that a partially
trusted callers can use your wrapper to call Win32 without having
unmanaged code access.

dominick

I have an application which use has a DLL with 100+
(auto-generated) Managed C++ wrapper around some native API.

Compare to a purely version my application has some performance
issue and I just realized it is probably due to the security
check which happen just before each of the (numerous) call into
this native API.

Now I know that, perhaps, I could tag my MC++ wrapper with
<SuppressUnmanagedCodeSecurityAttribute>

But I wonder if there is not an other call I could place in the
Main() function (such as Permission.Demand() or stuff like that)
which will achieve the same result?

After all my code this is for a desktop application with as much
right as the user.
 
R

Robert Simpson

Turing on that attribute will drastically improve performance ...

I'm using it in my SQLite ADO.NET 2.0 provider, which calls the native
database engine. I was floored at how close the performance was to raw
unmanaged C++ ...

I did a few performance benchmarks comparing raw native C++ to ADO.NET C#:

http://sqlite.phxsoftware.com/forums/thread/37.aspx

Robert

Lloyd Dupont said:
Ho... this Assert?

I didn't know about it!
It's why I was asking!

I though you were talking about System.Diagnostic.Assert
I though it was non sensical!


I should have know better!
Someone who thinks SUCS is an understandable acronym is likely to have a
second meaning! ;-)


Dominick Baier said:
:) that's what i said...

dominick
This one!

CodeAccessPermission.Assert()

Anyway, it's not as good as
SupressUnmanagedCodeSecurityAttribute
in message
Ah ok - adding SUCS will not improve performance - replacing Assert
with SUCS is usually a perf improvement.

Well I don't have any plugin API so there is no problem....

But my question was: is there a replacement of [SUCS] ? like using a
demand or similar stuff?

"Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com>
wrote in message

SUCS is indeed a significant performance improvement for unmanmaged
calls. Not sure if it applies to your scenario - but give it a try.

Just be aware of the implications - this means that a partially
trusted callers can use your wrapper to call Win32 without having
unmanaged code access.

dominick

I have an application which use has a DLL with 100+
(auto-generated) Managed C++ wrapper around some native API.

Compare to a purely version my application has some performance
issue and I just realized it is probably due to the security check
which happen just before each of the (numerous) call into this
native API.

Now I know that, perhaps, I could tag my MC++ wrapper with
<SuppressUnmanagedCodeSecurityAttribute>

But I wonder if there is not an other call I could place in the
Main() function (such as Permission.Demand() or stuff like that)
which will achieve the same result?

After all my code this is for a desktop application with as much
right as the user.
 
L

Lloyd Dupont

Anyway Interop has a cost and it seems you can't get away with it...
Pff...


--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
Robert Simpson said:
Turing on that attribute will drastically improve performance ...

I'm using it in my SQLite ADO.NET 2.0 provider, which calls the native
database engine. I was floored at how close the performance was to raw
unmanaged C++ ...

I did a few performance benchmarks comparing raw native C++ to ADO.NET C#:

http://sqlite.phxsoftware.com/forums/thread/37.aspx

Robert

Lloyd Dupont said:
Ho... this Assert?

I didn't know about it!
It's why I was asking!

I though you were talking about System.Diagnostic.Assert
I though it was non sensical!


I should have know better!
Someone who thinks SUCS is an understandable acronym is likely to have a
second meaning! ;-)


Dominick Baier said:
:) that's what i said...

dominick

This one!

CodeAccessPermission.Assert()

Anyway, it's not as good as
SupressUnmanagedCodeSecurityAttribute
in message
Ah ok - adding SUCS will not improve performance - replacing Assert
with SUCS is usually a perf improvement.

Well I don't have any plugin API so there is no problem....

But my question was: is there a replacement of [SUCS] ? like using a
demand or similar stuff?

"Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com>
wrote in message

SUCS is indeed a significant performance improvement for unmanmaged
calls. Not sure if it applies to your scenario - but give it a try.

Just be aware of the implications - this means that a partially
trusted callers can use your wrapper to call Win32 without having
unmanaged code access.

dominick

I have an application which use has a DLL with 100+
(auto-generated) Managed C++ wrapper around some native API.

Compare to a purely version my application has some performance
issue and I just realized it is probably due to the security check
which happen just before each of the (numerous) call into this
native API.

Now I know that, perhaps, I could tag my MC++ wrapper with
<SuppressUnmanagedCodeSecurityAttribute>

But I wonder if there is not an other call I could place in the
Main() function (such as Permission.Demand() or stuff like that)
which will achieve the same result?

After all my code this is for a desktop application with as much
right as the user.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top