Note that there are some explanatory texts on larger screens.

plurals
  1. POSlow reflection with NHibernate (additional call of CodeAccessSecurityEngine)
    primarykey
    data
    text
    <p>I've got serious problem with our application. We are developing GUI application + server which can be used in two different purposes.</p> <ol> <li>GUI application invoking embedded server which runs in the same process as embedded server</li> <li>GUI application is communicated with separated standalone server application via REST - separated process.</li> </ol> <p>We are using spring.net so there are small differences between both solutions. Server is just one context so the solution #1 instantiates it directly as new spring.net context and solution #2 has two exe files: GUI.exe + standalone server exe. As I already said, both application flows are almost the same.</p> <p>Whats the issue? Standalone server is three times slower than solution #1. It means separated standalone server application is three times slower than embedded one.</p> <p>I've used DotTrace and find the find the reason in 10 minutes. Server uses NHibernate which get/set properties via reflection very often.</p> <p>In the first solution when GUI application hosted in embedded server, reflection is very quick. But when it's on separate standalone server perform, reflections tasks are very slow.</p> <p>Here are stack traces for slow solution:</p> <pre><code> - 5,874 ms System.RuntimeMethodHandle.PerformSecurityCheck(Object, IRuntimeMethodInfo, RuntimeType, UInt32) - 4,642 ms System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32, PermissionSet) - 36ms System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack, PermissionSet, PermissionSet, PermissionSet, RuntimeMethodHandleInternal, RuntimeAssembly, SecurityAction) - 1ms System.Reflection.RuntimeMethodInfo.get_Value </code></pre> <p>Fast solution:</p> <pre><code> - 5 ms • 10,740 calls • System.RuntimeMethodHandle.PerformSecurityCheck(Object, IRuntimeMethodInfo, RuntimeType, UInt32) - 1 ms • 10,740 calls • System.Reflection.RuntimeMethodInfo.get_Value </code></pre> <p>As you can see, the slow solution killer is the aditional call to System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper. Standalone server should automatically run as full trusted as well as GUI does.</p> <p>Do you have any solutions how to switch this check off or how to set up the standalone server application? When I compare both app.configs, i'm not able to find any difference regarding described issue.</p> <p>EDIT:</p> <p>We have finally investigated the reason and the solution was the only clear.</p> <p>Standalone server instantiates spring.net's context with using <strong>ContextRegistry.GetContext()</strong> but embedded one uses standard <strong>new XmlApplicationContext(new[] {"..."})</strong>. This simple difference results into so significant performance hit.</p> <p>It seems that spring's app.config context handler do "any wrong stuff" but we have not time to investigate the real purpose yet.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload