views:

204

answers:

3

Hi,

I tried to build a very very small .NET app in F#.

It just has to convert a small string into another string and print the result to the console like:

convert.exe myString ==> prints something like "myConvertedString"

I used dottrace to analyze the performance:

  • 26% (168ms) in my actual string conversion (I thinks this is ok.)
  • 65,80% (425ms) in ResolvePolicy in System.Security.SecurityManager

A runtime > 500ms on every execution is way too slow. Can I do something to improve this?

It would be Ok if only the first call needs this time.

Regards, forki

+1  A: 

You could use caspol.exe to turn code access security check off.

Darin Dimitrov
+7  A: 

Do you definitely have to run this as a separate process for each string?

Could you pass in the name of a file containing a lot of strings? That would be significantly more efficient, in terms of:

  • Time taken to bring up a process
  • Time taken to load all the various bits of .NET
  • Time taken to JIT your code
  • Time taken to resolve the security policy
Jon Skeet
Yeah, whole application overhead is hard here. REALLY hard on micro applications (that incidentally serve hardly a practicap purpose).
TomTom
I know. But that's not possible here. The problem is: From time to time there is a single string which needs to be converted.
forki23
@forki23: If it's "from time to time" does it really matter if it takes 500ms or so? What are you calling this from? Could you turn your app into a small server which stays up and responds to TCP requests instead?
Jon Skeet
Thinking about the whole process gave me the idea to cache already converted strings in the second tool.
forki23
+1  A: 

you could try to precompile the assembly. with the program ngen it is possible to compile a .net assembly already to machine code, and then to install the assembly in the global assembly path. that should speed up the loading time of the application