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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Daganev
Beginner


Joined: 11 Jun 2006
Posts: 20

PostPosted: Tue Dec 30, 2008 6:48 pm   

Best coding practices
 
I searched the forums and didn't see a thread on this, so I'm just making this request.

Can the forums collect into a single thread, all the "best practices" for Cmud so as to maximize speed on large systems. (i.e. IRE combat and healing systems)

I saw in one thread that you shouldn't use #EXEC if possible, but then on the %item thread, it says you should use #EXEC, but is #SEND better? Things like that.

another optimization question I have about CMud is regarding enabling and disabling classes.

Thanks.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Dec 30, 2008 7:31 pm   
 
Trouble is that a lot of these things vary depending on what exactly you're doing, and speed isn't the only goal in many circumstances, so saying unequivocally that one method is better than another is very difficult. Similarly, saying something is slower than something else doesn't say how much slower it is, and a marginal speed gain isn't always worth the hassle of changing things around and using more complex methods.

So first, the easiest way to find out if something is faster is to try it and see. If you're in doubt about something, just have a go and see what happens.

But you're right that there're plenty of things that people often get wrong, and if you have any questions about that sort of thing, I think this thread would be a good place to ask them. I encourage you to point people in this direction if anyone has that sort of query.

Onto your questions - the reason that #exec is slow is because it has to be parsed and then compiled every time it runs - in zMUD, this happened every time any script ran, but in CMUD, the normal scripts are only parsed and compiled the first time they're run after CMUD starts, and then the compiled code is stored an executed again as needed. So in CMUD, using #exec and making CMUD parse your command every time is much slower than just running the command yourself.

#send will presumably be faster because it doesn't parse the text in any way - you can see this difference if you do the following:

#alias test {blah}
#exec "test;lol"
#send "test;lol"

The #exec version will send two separate commands - test and lol. The #send version will send a single command, "test;lol". So it's not parsing the alias or the semicolon - it's just not looking for them, which will speed it up, but #exec is the only way to call an alias or run multiple commands where you don't know the commands beforehand. So use #send if you can, but only when you're sure you're never going to get a bad result from it.

Similarly, #sendraw will probably be faster than using #send. #send is still parsed for oninput triggers and also displays a line to the screen, both of which #sendraw doesn't do. But you might want that text displayed to the screen, so testing to see whether or not there's any appreciable gain would be worthwhile - it'll probably depend on the number of oninput triggers you have.

The tl;dr version is to use #sendraw unless you need to use #send, and to use #send unless you need to use #exec. If you have a script that you think needs #exec, you should probably consider if there isn't a different way of doing it that'd use a faster command.

What's your question about enabling and disabling classes?
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Daganev
Beginner


Joined: 11 Jun 2006
Posts: 20

PostPosted: Fri Jan 16, 2009 5:55 pm   
 
Does having too many alarms slow down cmud?

How many is too many?

IS it better to have alarms constantly running, or to keep createing temporary alarms?

Thanks
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Jan 16, 2009 6:04 pm   
 
As far as I know, creating and destroying this is slower than enabling and disabling things, but it can also be damned inconvenient to have to keep enabling and disabling an alarm.

And it shouldn't any more than having too many of anything would slow down CMUD.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion 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