emval_get_global() - can we make it faster?

52 views
Skip to first unread message

Lilit Darbinyan

unread,
Jun 25, 2019, 11:29:21 AM6/25/19
to emscripten-discuss
embind currently generates the following glue code for accessing the global object:

function emval_get_global() { return (function(){
   
return Function;
 
})()('return this')(); }


This function is called every time we access emscripten::val::global() from C++, e.g. 

val Object = val::global("Object");

It turns out it's pretty slow in SpiderMonkey - running this function in a loop 10,000 times we see that it takes on average 117 ms in SpiderMonkey compared to 17 ms in V8.

I shall raise this slowness issue with SpiderMonkey separately, but I am wondering if there is room for improvement here on the emscripten side as well - for example, would it make sense to cache this value, or make use of the new globalThis instead?

Mathias Bynens

unread,
Jun 26, 2019, 4:46:33 AM6/26/19
to emscripten-discuss
+1 to using globalThis, and falling back to the current approach or a more robust polyfilling mechanism.

Sergey Rubanov

unread,
Jun 26, 2019, 5:28:10 AM6/26/19
to emscripte...@googlegroups.com
+1, this also unlocks usage of emval_get_global in scripts with unspecified `unsafe-eval` in CSP.

-- 
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/3a5e63e7-fc8c-48a4-9414-df6ad50a0eee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alon Zakai

unread,
Jul 2, 2019, 1:37:20 PM7/2/19
to emscripte...@googlegroups.com
Thanks everyone, definitely sounds like a good idea!


- Alon


Reply all
Reply to author
Forward
0 new messages