On 5/21/22 1:52 PM, Bram Moolenaar wrote:
In a performance sensitive function I recently used vim's `and(arg1,
arg2)` and `or(arg1, arg2)` since I couldn't find `&`,`|`. Got me
wondering what the difference is between a function and vim9
instruction execution; so I was interested in taking a look at how
this instruction executes.

I guess if invoking `and()` involves setting up a stack frame then the
difference is pretty big.
Unfortunately, yes, a function call has quite a bit of overhead.
Especially now that expressions are converted to byte code when
compiling.  A function call still has to handle all kinds of possible
side effects.  I wonder if we can make a difference between calling a
user defined function and a builtin function, since the latter should
have predictable behavior.

My first thought was that you'd want a flag for each builtin that indicated if it could be inlined-call in a compiled :def, when it had no side effects. But I guess the side effects you speak of are to the script context and it's variables. I don't know if there are any builtins that have access to the vim9 script context, I'd guess they shouldn't be inlined. Certainly and(), or(), xor() no side effects anyway you look at it. I guess calling f_and() is same order of magnitude as handling it through ISN_OPNR.

Hmm, I don't see a not(), bitwise complement, function. Called something else? I guess you can do
val = -val - 1. Does that work on negative numbers?

-ernie

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/0d3d148a-fbac-9d27-159f-e938a22794af%40raelity.com.

Raspunde prin e-mail lui