Talk:Code Sizer

From Second Life Wiki
Revision as of 18:03, 19 October 2007 by Ppaatt Lynagh (talk | contribs) (add one section to guess how the plus four instrument, add one section to blog the design rationale behind the Code Sizer instrument)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The Plus Four Instrument

Part of the inspiration for beginning to teach new people how to measure byte code size was the following fragment from Talk:Hex

[... snipped ...]
My steps are below:
  1. Compile and execute default{state_entry(){llOwnerSay((string)llGetFreeMemory());}} to establish a baseline
  2. Paste an implementation at the top of script from #1, compile and run.
  3. Subtract the result from #2 from the result of #1; you now have the bytecode cost.
  4. Repeat steps #2 & #3 for each implementation.
[... snipped ...]

I call that the "plus four" instrument, since so far as I know, quoting from the Code Sizer article:

Note: Take care to avoid falling into the easy error of printing llGetFreeMemory() before and after you delete the last function of the script. Adding the first function to the script costs an extra 4 bytes. Only people who understand LSO know why, and they haven't yet published that explanation anywhere near here.

Why The Code Sizer Article Exists

The LSL Script Efficiency article says "Efficiency is how much resource a particular script uses to accomplish a goal".

Yes exactly.

We should measure not only LSL Script Efficiency#How_Fast_Does_That_Code_Run but also how small is that code, as is conventional in academic and commercial computer science. When we rewrite code to produce equivalent results more efficiently, we trade brevity and clarity and conventionality and space and time off against one another. LSL can only measure space and time. We should show exactly how to measure both of those, in order to invite more people to make such measurements, to build a consensus science of how to write small and fast LSL code.

LSL gives us llGetFreeMemory to measure how small is that code, just as LSL gives us llGetTimestamp to measure how fast does that code run. We the LSL wiki authors have written the Code Racer and Efficiency Tester articles to show how to call llGetTimestamp to measure how fast does that code run. Now likewise we should write an article to show how to call llGetFreeMemory to measure how small is that code.

I guess we should publish that article separately. Here it is now.