C Function calls from JS after faster than JS function calls? #225
-
I ran this on multiple devices and found C function calls to be faster than JS function calls in quickjs. I want to know if this is really possible? How can a js call be slower than calling a c function from JS. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Can you share an example? |
Beta Was this translation helpful? Give feedback.
-
It's not too surprising because quickjs has to perform a fair amount of bookkeeping on JS function entry (and, to a lesser extent, exit.) Both the C and JS function don't really do anything except return so that bookkeeping turns into significant overhead for the JS function, whereas the C function is probably literally only two or three assembly instructions. If anything, I'm surprised the gap isn't bigger! |
Beta Was this translation helpful? Give feedback.
It's not too surprising because quickjs has to perform a fair amount of bookkeeping on JS function entry (and, to a lesser extent, exit.)
Both the C and JS function don't really do anything except return so that bookkeeping turns into significant overhead for the JS function, whereas the C function is probably literally only two or three assembly instructions. If anything, I'm surprised the gap isn't bigger!