Reducing the overhead of strings in dictionaries
Root / Programming Questions / [.]
kldck_hulCreated:
Hi all,
I wrote a language extension that looks up a string in a fake dictionary. When users are using this, it seems like an awful lot of garbage strings are created:
DEF update clamp "X","W" clamp "Y","H" ENDX,Y,W,H are all keys in a dictionary. Would it be beneficial to create an X$, Y$, W$, and H$ at the beginning of the program to avoid creating strings for the dictionary keys a lot? EDIT: I've noticed that SPANIM takes a string argument a lot like my dictionaries can:
SPANIM Management number,"Animation target",... Animation target Numerical value or character string to control the elements that should changeIs it common to see the target as a string? Is it an optimization to change these to a number?
I tested this a few times while at work today, running through a couple million iterations with different strings.
Every test varied by at most 6 frames, which was about a 0.3% difference. Using a variable was unanimously "slower". I wonder if strings are created from arrays the same as they are from literals, which means the extra frames are time spent looking up the memory reference.
I found that "" is actually slower than using a variable however. I wonder if this is because an array isn't allocated every time.
Let me know if my findings are way different than someone else found. The test varied by so little, I'm wondering if theres some optimization taking place that I'm not aware of. I've been told smilebasic doesn't have constant strings.