1

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

forki23
  • 2,784
  • 1
  • 28
  • 42
  • 1
    You could always get a cup of coffee while you wait ;-) Seriously, have you thought about making it a singleton COM service? – James Hugard Mar 18 '10 at 15:38

3 Answers3

7

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
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Yeah, whole application overhead is hard here. REALLY hard on micro applications (that incidentally serve hardly a practicap purpose). – TomTom Mar 17 '10 at 11:11
  • 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 Mar 17 '10 at 11:13
  • 1
    @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 Mar 17 '10 at 11:41
  • Thinking about the whole process gave me the idea to cache already converted strings in the second tool. – forki23 Mar 17 '10 at 11:42
1

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

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

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

user287107
  • 9,286
  • 1
  • 31
  • 47