|
Daisy Rimbaud
Registered User
Join date: 12 Oct 2006
Posts: 764
|
07-16-2007 01:12
I'm trying to cut down a script that is too large to compile. The problem is, I'm not sure what is most needed to get rid of. For instance, I tend to lay out my scripts with lots of line breaks. If I scrunched everything up, would that save memory?
Are any elements of LSL particular memory hogs (e.g. character literals, lists)?
|
|
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
|
07-16-2007 01:53
I'm no expert but I believe lists will impact on your memory usage. A lsit of 500 names in a Greeter script for instance will definately put a large demand on the memory possibly causing a stack heap overflow when the script runs. From: Newgate Ludd Remember that LSL is pass by value so any strings or lists that are being manipulated are being copied each time. This can/does eat memory especially if you are not using the hacks to recover what you can each time. In terms of compiling memory I'm sorry I don't know if deleting line breaks will help.
|
|
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
|
07-16-2007 03:46
We are not talking about running the script but compiling it. My experience has been that the compiler loses its stack very easily. Each block (if, while, function calls, etc, seems to increase the stack untill the compiler has no more space to run its compilation.
lslint seems to be able to figure out when that compiler limit it reached and is worth running over your scripts.
This is something the open source client developer community might be able to fix.
Meanwhile, we are continually dividing our scripts and coping with the vagaries of llMessageLinked.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
07-16-2007 05:39
Yeah, I don't think the compiler will use more memory with more whitespace or comments in the script formatting. Instead, I'd focus on anywhere the script uses the same string literal multiple times (replacing that with a variable), or repeats the same block of code with minor variations (replacing that with a function call). On the other hand, if a function is only called from one place in the script, you can save a little bit by pulling that code out of the function and back into the script.
Ultimately though, as ed44 says, anything substantial will end up as multiple communicating scripts. Then the art is to break up the code "elegantly" such that the division makes functional sense, minimizes the frequency of comms between the scripts, and still fits each script within memory limits.
|
|
Daisy Rimbaud
Registered User
Join date: 12 Oct 2006
Posts: 764
|
07-16-2007 08:15
I've removed a chunk of functionality which now allows the script to compile. I'll try and reduce the functionality with a second script, but it may be hard because of the number of shared variables.
Now I'm trying to defend the main script against stack-heap collisions. I guess anything I can do to cut out string literals will help here? There are a lot of llSay calls that I might be able to farm out.
|
|
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
|
07-16-2007 08:31
Strings can take up huge amounts of memory, depending on how large they are. I had a script that was generating reports, that would take 3-4k for just that string.
What I ended up doing was farm out my Instant Messages to another script, which would hold them in a queue until either told to send them or until the string hit a certain size.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
07-16-2007 09:26
It's a little hard to generalize here without knowing a bit about what the script does. Strings (literals or variables) can be memory hungry, as can lists (not all that many UUIDs fit in 16KB, for example). For complex scripts, I often end up with a main script that just orchestrates overall flow, with subscripts handling easy-to-carve-out functionality (dialogs and associated user interaction are prime candidates here, cuz they tend to have a lot of strings and usually don't depend on too much global state--and link_message delay is negligible compared to click-time.) Worst case, one can use scripts that just wrap memory in set/get link_messages--but that's only practical for relatively infrequently-accessed data.
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
07-16-2007 21:44
everything uses up memory except comments and whitespace
the only real major GOTCHA ! are list's each element uses their respective space + 40 bytes
|