Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

A little Mono Catch-22

Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
12-30-2008 00:26
The internal script memory overhead for function calls is so high in Mono, it's led to this little conundrum...

Q: How do I make large scripts easier to write and maintain?
A: Break out your code into functions.
Q: What's the most effective way to save memory in large scripts?
A: Inline your functions.

Ugh.

/esc

Mono... from the people who brought you D-COM.
_____________________
http://slurl.com/secondlife/Together
Ee Maculate
Owner of Fourmile Castle
Join date: 11 Jan 2007
Posts: 919
12-30-2008 01:10
Sorry for being dense, but what does inlining mean?
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
12-30-2008 01:58
:) It just means putting the body of the function back into the main code, avoiding the function call altogether -- it's harder to MUCH harder to maintain especially as your script grows, but if you get stuck for memory it can save you 1/2 to 1k of memory.
_____________________
http://slurl.com/secondlife/Together
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
12-30-2008 02:41
DANG! How can that be? PER STACK FRAME, or average for a decent sized script?
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
12-30-2008 02:50
From: Hewee Zetkin
DANG! How can that be? PER STACK FRAME, or average for a decent sized script?

Well, I had a big script that hit the compile size limit, inlined the smaller functions and got back about 5k or more... it shocked me too and seems to be progressively more pronounced as the script grows in length. I've done no fancy testing to establish the exact effects, I must admit.
_____________________
http://slurl.com/secondlife/Together
Ollj Oh
Registered User
Join date: 28 Aug 2007
Posts: 522
12-30-2008 04:11
Memory is a cheap ressource.
time is not.

Make functions for every small shit.
When you hit a memory limit reduce functions that are only called from one place.
Ee Maculate
Owner of Fourmile Castle
Join date: 11 Jan 2007
Posts: 919
12-30-2008 04:29
Hmm.. interesting. Thanks for clarifying :)
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
12-30-2008 10:33
Ollj has it right, function should be made for things that happen more then once. If you have a function that executes only once, and your looking to get as much memory as possible, put those functions in the main body (and comment them of course for future date) but if it's something that gets executed numorous times, it is cheaper (in theory, not sure how the compiler actually works) to put that in a function.