Forums

Static linking of Cobra applications

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Static linking of Cobra applications

Postby johannes.krampf » Thu Dec 16, 2010 3:06 pm

I already answered my own question, but the answer might be interesting for someone else.

Static linking is possible with mono. Use the following command to create a native executable without mono dependencies. Alternatively you can also bundle all libraries and only have a dependency on mono.

Code: Select all
$ mkbundle --deps --static fib.exe -o fib-static # fully static - runs on computers without mono
$ mkbundle --deps fib.exe -o fib-bundle # bundle - runs on computers with mono, but without Cobra
$ ls -hs fib-* # however: ouch
6,3M fib-bundle  9,2M fib-static


This seems only useful if you want to execute your Cobra code on a machine without mono. Start up time is a lot slower compared with running the exe in mono. Compressing the binaries helps with the file size (~40% reduction in my limited test), but worsens start up time further.
johannes.krampf
 
Posts: 11
Location: Suisse Romande

Re: Static linking of Cobra applications

Postby Charles » Fri Dec 17, 2010 2:58 am

I wonder why the start up time is worse. Do you have any measurements to share or was it just an obvious delay when you ran the program?

You might be interested in the -turbo option which speeds things up primarily by turning things off (contracts, assert statements, unit tests, nil checks). See "cobra -h".
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Static linking of Cobra applications

Postby johannes.krampf » Fri Dec 17, 2010 3:37 am

Short answer: I expected start-up time for bundles to be worse. The start-up time is actually good (about as fast as python) when using the -turbo option.

I did this to see how useful Cobra can be for scripting. Start-up time matters when executing something many times and not needing mono would be a big plus for server side code. It's good for scripts, but I wouldn't use it without mono.

---

If mono supported removal of unused data and functions (like gcc's options "-ffunction-sections -fdata-sections -Wl,--gc-sections"), this would be a lot more useful, but I guess this takes a lot of static analysis.

It's imho no wonder that the start up time is worse. Have a look at the file sizes for bundles - putting the DLLs and/or the whole mono runtime inside has some effect on the file size.

Code: Select all
$ mkbundle --deps hello.exe -o hello-bundle
$ mkbundle --deps --static hello.exe -o hello-static
$ mkbundle -z --deps hello.exe -o hello-compressed-bundle
$ mkbundle -z --deps --static hello.exe -o hello-compressed-static
$ ls -sh hello-*
6,3M hello-bundle             5,2M hello-compressed-static
2,3M hello-compressed-bundle  9,2M hello-static


Just to qualify this: The start up time goes from around 100ms to 200ms for bundles and 300ms for compressed bundles. All executables are cached in memory (the first time, when the files are loaded from disk, it takes about 400ms for a bundle) This is cobra without optimization.

To compare: A python hello-world script takes about 33ms to execute, a C#-program 26ms and a compiled C program 2ms. With the turbo option, cobra takes about 37ms.

Code: Select all
$ time mono hello.exe
Hello, world.

real   0m0.107s
user   0m0.090s
sys   0m0.013s
$ time ./hello-bundle
Hello, world.

real   0m0.242s
user   0m0.223s
sys   0m0.013s
$ time ./hello-static
Hello, world.

real   0m0.225s
user   0m0.217s
sys   0m0.007s
$ time ./hello-compressed-bundle
Hello, world.

real   0m0.321s
user   0m0.297s
sys   0m0.020s
$ time ./hello-compressed-static
Hello, world.

real   0m0.308s
user   0m0.293s
sys   0m0.013s
$ time mono hello-cs.exe
Hello World

real   0m0.026s
user   0m0.017s
sys   0m0.007s
$ time mono hello-turbo.exe
Hello, world.

real   0m0.037s
user   0m0.027s
sys   0m0.010s
$ time python hello.py
hello, world

real   0m0.033s
user   0m0.023s
sys   0m0.007s
johannes.krampf
 
Posts: 11
Location: Suisse Romande


Return to Discussion

Who is online

Users browsing this forum: No registered users and 21 guests