a builtin verses a moo coded verb

1 view
Skip to first unread message

Nathan Smith

unread,
Nov 20, 2017, 8:35:55 PM11/20/17
to MOO Talk
hello folks
Just a quick question for y'all tonight.
Is a builtin more efficient than a moo code that does the same thing.
The reason I ask this, is because I was experimenting with is_player(player), and $ou:isa(player, $player);
Now, is_player() uses about 4 times less ticks than isa, give or take, however, is_player is a builtin, and so we can assume blocking.
Which one, there more, is best to use.
If $ou:isa is the way to go, would it be worth putting some code it that forces any call to is_player to just be rerouted to $ou:isa?
Thanks muchly

Wolfgang Faust

unread,
Nov 20, 2017, 9:45:28 PM11/20/17
to Nathan Smith, MOO Talk
In general, the number of ticks used directly corresponds to CPU usage, so code that uses fewer ticks is more efficient. What does the implementation of $ou:isa() look like? All the is_player() builtin does is check the FLAG_USER on the object (plus some argument shuffling); I'm not sure how MOO code could do that without calling the builtin, or be more efficient than an array index plus a bit shift.

MOO code is also blocking unless it explicitly calls suspend() or related functions; I'm not sure why isa would need to do that.

--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+unsubscribe@googlegroups.com.
To post to this group, send email to MOO-...@googlegroups.com.
Visit this group at https://groups.google.com/group/MOO-talk.
For more options, visit https://groups.google.com/d/optout.



--
The views expressed above are exclusively mine, if anyone's.

Tim van Dijen

unread,
Nov 21, 2017, 5:36:56 AM11/21/17
to MOO Talk
is_player() and $object_utils:isa do completely different things, so there's no way to compare them.

But to answer your other question:  yes, builtins can be more efficient (if well programmed), simply because it doesn't have to be converted from MOO to bytecode.
However, on nowadays hardware, a few ticks more isn't gonna hurt your MOO's performance. Also, builtins are difficult to write, can't be modified on the fly and come with risk of memory leaks (if not well programmed).
My advice would be to just start programming very efficient MOO-code, rather than moving MOO-code to builtins.

- Tim

Nathan Smith

unread,
Nov 21, 2017, 10:21:58 AM11/21/17
to MOO Talk
Hi there.
Thanks for your responses. I appreciate your advice on this matter. Are there any documents/files you recommend as a good read for task efficiency?
I feel I know most of what there is to know about best practices and the the like, such as the less ticks, the better... don't use multiple instances of $list_utils:slice(prop), just put it in a variable, and refer to that, ETC.
I just wondered if there were any good reads for such things.

Also a related question. With the queued_tasks() builtin, if you sort that list by the second elemnt, and remove any that have -1, will the first element in the list be the task that's about to be executed?
If not, I may look into a builtin[probabl self made] that returns the task that is next to be doing something. Thanks


On Tuesday, November 21, 2017 at 10:36:56 AM UTC, Tim van Dijen (Goblin) wrote:
is_player() and $object_utils:isa do completely different things, so there's no way to compare them.

But to answer your other question:  yes, builtins can be more efficient (if well programmed), simply because it doesn't have to be converted from MOO to bytecode.
However, on nowadays hardware, a few ticks more isn't gonna hurt your MOO's performance. Also, builtins are difficult to write, can't be modified on the fly and come with risk of memory leaks (if not well programmed).
My advice would be to just start programming very efficient MOO-code, rather than moving MOO-code to builtins.

- Tim
2017-11-21 3:45 GMT+01:00 Wolfgang Faust <wolfg...@gmail.com>:
In general, the number of ticks used directly corresponds to CPU usage, so code that uses fewer ticks is more efficient. What does the implementation of $ou:isa() look like? All the is_player() builtin does is check the FLAG_USER on the object (plus some argument shuffling); I'm not sure how MOO code could do that without calling the builtin, or be more efficient than an array index plus a bit shift.

MOO code is also blocking unless it explicitly calls suspend() or related functions; I'm not sure why isa would need to do that.
On Mon, Nov 20, 2017 at 8:08 PM, Nathan Smith <lordva...@gmail.com> wrote:
hello folks
Just a quick question for y'all tonight.
Is a builtin more efficient than a moo code that does the same thing.
The reason I ask this, is because I was experimenting with is_player(player), and $ou:isa(player, $player);
Now, is_player() uses about 4 times less ticks than isa, give or take, however, is_player is a builtin, and so we can assume blocking.
Which one, there more, is best to use.
If $ou:isa is the way to go, would it be worth putting some code it that forces any call to is_player to just be rerouted to $ou:isa?
Thanks muchly

--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+u...@googlegroups.com.

To post to this group, send email to MOO-...@googlegroups.com.
Visit this group at https://groups.google.com/group/MOO-talk.
For more options, visit https://groups.google.com/d/optout.
--
The views expressed above are exclusively mine, if anyone's.

--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+u...@googlegroups.com.

Michael Munson

unread,
Nov 21, 2017, 10:57:45 AM11/21/17
to Nathan Smith, MOO Talk
Moo tasks are interleaved on a single thread to simulate multitasking. Basically a task may execute one operation, then next on the stack may be an operation from a different moo verb. This stimulates both verbs operating simultaneously even though in reality they are operated synchronously. There’s no real way to specify or give priority or know which tasks are executing and which are in suspend.

Sent from my iPad
Reply all
Reply to author
Forward
0 new messages