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
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sun Jun 27, 2010 4:40 pm   

3.20 Script Speed
 
Is there anything that would make scripts run slower in 3.20? I have a Clan Highlighter Script and am now working on a Damage Script + Damage Calculator.

Both of them do a lot of stuff, such that I would almost expect them to lag but they both ran perfectly in 2.37. However, having now upgraded to 3.20 BETA these scripts are suddenly running awfully slow. I could paste the whole scripts, but they require a lot of data from the MUD itself to function properly. However, if you could tell what might be slowing them down by looking at them I will.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Jun 27, 2010 5:08 pm   
 
Yes. One of the bigger ones is the variable-by-reference in functions. Consider the following:

varname = %additem("item",@varname)

In this example, a second copy of @varname is created so it can be sent to the %additem() function. In addition, a third copy of the variable is created that includes "item" so it can be returned as a result. This is a by-value call and obviously it's pretty inefficient.

To call a variable by reference, you drop the @ just like when using #commands:

varname = %additem("item",varname)
_________________
EDIT: I didn't like my old signature
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sun Jun 27, 2010 5:21 pm   
 
So, dropping the @ will allow me to increase the speed and efficiency back to 2.37 levels?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Jun 27, 2010 5:35 pm   
 
There are many more things, but yeah. For example, do you use the %eval() function in any of your code? If you do, remove the %eval and just use (). %eval() is a runtime function and thus about as slow as #EXEC.
_________________
EDIT: I didn't like my old signature
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sun Jun 27, 2010 5:41 pm   
 
I have a tendency to use %eval(), but I also have a tendency to see odd weird errors when I don't use it. Still, I'll try using () where I can. Thanks.

EDIT: Does this by-reference thing matter with var=@var too?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Mon Jun 28, 2010 12:21 am   
 
This feature isn't backwards compatible with 2.37, is it? It seems any scripts I've updated with it no longer function with 2.37.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Mon Jun 28, 2010 12:37 am   
 
No, it's a feature that's new with the latest beta versions. Really, you should be on 3.21, by the way, and not 3.20.

Also, if you experience anything with %eval not working, you need to post about it as well. Keep in mind that using (expressions) within {} or "" will cause them to print literally instead of evaluating the expression, so you'll need to use %eval in situations such as:

#SAY {3+4 is %eval(3+4)}

or

#SUB {The answer is %eval(3+4)}

and so on.

Charneus
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Mon Jun 28, 2010 12:53 am   
 
Concat works as well and should be faster..

#Say %concat( "3+4 is ", (3+4))
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Mon Jun 28, 2010 12:56 am   
 
I'm on 3.21 Razz
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Jun 29, 2010 4:35 pm   
 
Quote:
So, dropping the @ will allow me to increase the speed and efficiency back to 2.37 levels?

Actually, none of the new stuff should be slower than 2.37. Even with using @ with the list names it is still faster than 2.37. So there is something else wrong somewhere in your scripts.

What I suggest is turning on the Script Debugger window and run the same script in 2.37 and in 3.21 and compare the timestamps in the debugging window to try and pin down which script is slowing you down and then start adding some #DEBUG statements to the script to see if you can determine which part of the code has changed.

Even stuff like %eval, while it is slow, isn't any slower in 3.21 than in 2.37.

But since this problem is specific to your scripts and your scripts are complicated, it's really up to you to do the debugging work to narrow down the problem to something we can help more with.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Jun 30, 2010 3:30 pm   
 
Well, oddly enough, the script speed went back to 2.37 levels after changing all the variables to by-reference instead of what they were. But we're talking about lists with close to 2000 members, maybe that makes a difference?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Jun 30, 2010 4:28 pm   
 
It's possible that for some function combinations that the old hash tables in 2.37 didn't make a copy of the table and were essentially using the "by reference" concept. Of course, this would cause bugs in 2.37 because changing a by-reference list that hasn't been copied might end up changing the table stored in a different variable. v2.37 was rather inconsistent about all of that. So what you said makes sense.

It would be nice to have the functions use "by reference" by default for speed, but unfortunately everybody in older versions of CMUD are using the @ in front of the list and there is no way @varname should ever do a direct "by reference". So for backwards compatibility, there is no way to get the speed improvement automatically. People will need to edit their scripts to remove the @ where they want the by-reference speed.
Reply with quote
dbosst
Apprentice


Joined: 15 Jun 2010
Posts: 121

PostPosted: Thu Jul 01, 2010 3:56 pm   
 
is there a list of which functions support variable by reference?
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Jul 01, 2010 4:17 pm   
 
Actually, the more I thought about this, the more confused that I got.

In 3.2x, any function that accepts a list/table for "read only" access (like %db, %item, %numitems, etc) always uses the "by-reference" regardless of whether you use @ or not. So these functions should not be slower than 2.37 even with the presence of the @ character.

Here is the list of functions effected by "by-reference":

Write-access list: @list makes a copy, list is "by-reference"
%additem
%delitem
%delnitem
%push
%replaceitem

Write-access table/dbvar: @table makes a copy, table is "by-reference"
%addkey
%delkey

Read-only access list or tables: no difference between list and @list. Both are "by-reference"
%db
%dbitems
%dbkey
%dbkeys
%dbvalues
%iskey
%ismember
%isvalue
%item
%numitems
%numkeys
%numwords

So your script from 2.37 will only be slower in some cases when using @list with the "Write Access" functions shown above. And any case where this is slower than in 2.37 indicates a bug in v2.37 where it was not making a copy of the table and could cause weird script side-effects with changing the underlying list value.
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 Wolfpaw.net