Register to post in forums, or Log in to your existing account

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum

Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Mar 28, 2006 9:16 pm   

Some preliminary Compiled script speed results
I'm in the middle of working on the compiled script routines for CMUD. I've got some speed results for some simple expressions that I wanted to share with you.

The importance of these numbers is that because the expressions are simple, the times are dominated by parsing and execution overhead. Obviously, more time consuming expressions (such as division, etc) will wash out the differences and become dominated by the math time.

But since most zMUD scripts consist of simple expressions and variable lookups, these speed tests will give you a good idea of what you might expect in CMUD.

For each of these expressions I have gathered three time values. Each time is the number of milliseconds for 1,000 loops.

Time1: Normal zMUD expression parsing and evaluation
Time2: CMUD compile time
Time3: CMUD execution time (of compiled expression)

Expression 1: 3+4*5
123, 127, 16

Expression 2: 1+2+3+4+5
195, 198, 17

Expression 3: ((((1+2)+3)+4)+5)
250, 319, 17

So, what you can see is that the time needed to compile the expression is similar to the zMUD parsing and execute time. It's important to realize that these two routines use completely different parsers. CMUD is using the Yacc-generated parser used by the syntax checker, whereas zMUD is using the old reliable parsing engine that it's always had. So we see that the Yacc-generated parser has finally been optimized to give similar results.

Of course, the important number is the execution time. At this point the execution time doesn't change for simple expressions. And it's about 10 times faster than the parsing.

So, the way all of this works in CMUD is that the first time a script (alias, trigger, function, etc) is parsed, it is also compiled. As we see, this doesn't cost much extra time at all over just the normal parsing. Then, the next time the alias, trigger, function, etc is executed, we simply execute the compiled code rather than reparsing it.

The resulting speed increase depends on how often the script is changed and executed. If the script isn't changed, then each time it runs it will be using the compiled code and will run 10 times faster. If the script changes each time and has to be recompiled each time, then it will be about the same as in zMUD. There will be a flag to disable compiling for individual scripts if that is needed, and CMUD also keeps track of which scripts can't be compiled (syntax errors, or syntax that the compiler can't deal with).

Once I get finished with the compiler, I will run some speed tests on some *real* scripts that I use for testing zMUD to see what the real-world speed increase might be. But these preliminary results were exciting enough that I wanted to share them with you.
Reply with quote

Joined: 09 Oct 2003
Posts: 459
Location: USA

PostPosted: Fri Apr 07, 2006 4:33 pm   
Out of curiousity, what events would constitute the re-compile of a script?
Ichthus on SWmud:
Reply with quote

Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Apr 07, 2006 6:48 pm   
Anything that changes the stored script. So, if you have an alias:

#ALIAS test {hello world}

and you then type

#ALIAS test {hello again}

then that has changed the stored script value and that causes the recompile flag to be set. Or, if you open this alias in the package settings editor and manually change the script. In the settings editor you can click a Compile tab to view the compiled code, which also forces an immediate recompile. So this allows you to compile stuff in advance if you'd like.

But it's important to keep in mind that compiling a script takes about the same amount of time in CMUD as executing the script does in zMUD. So even if something was changing your script every time that it ran, forcing it to recompile each time, then it's going to run about the same speed as zMUD.

In any case, changes that force a recompile should be pretty rare. It's only those cases where you are creating aliases on-the-fly within another script that might have this problem. But even then you probably execute the script more often than you change it.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by