v8 map performance

50 views
Skip to first unread message

dark...@gmail.com

unread,
Nov 28, 2017, 3:50:06 AM11/28/17
to v8-users
Hi.

I have big unordered_map in C++, like

std::unordered_map<uint32_t, MyObject>;

It contains more than 10 million elements, and i need about 10 thousand hits to map from js. What is the most productive way to pass it to JS?

1) I can add each item to v8 variable:

v8::Local<v8::Object> map;
map
.Set(context, key, value);

But how productive it will be? And what type of v8::Object i must use? (v8::Object or v8::Map)?

2) I can use NamedProperty, but each access to map from js will call my c++ func. It's now slow?

And what kind of named properties should I must use in this variant? I see at least (SetAccessor, SetNamedPropertyHandler, SetHandler from v8::ObjectTemplate) and (SetAccessor, SetAccessorProperty, SetNativeDataProperty from v8::Object)

dark...@gmail.com

unread,
Nov 28, 2017, 3:53:39 AM11/28/17
to v8-users
i need read only access to map from JS.

Ben Noordhuis

unread,
Nov 29, 2017, 7:09:31 AM11/29/17
to v8-users
I would recommend to benchmark both approaches and see for yourself.

Intuitively, I would say that an accessor is going to be faster
because the number of lookups is much smaller than the number of keys,
but performance characteristics are frequently counter-intuitive.

dark...@gmail.com

unread,
Nov 29, 2017, 3:48:42 PM11/29/17
to v8-users


среда, 29 ноября 2017 г., 15:09:31 UTC+3 пользователь Ben Noordhuis написал:
Thanks! But what type of access do you recommend using? There are a lot of them, and unfortunately, I do not really understand what exactly they are different about

dark...@gmail.com

unread,
Nov 29, 2017, 11:27:16 PM11/29/17
to v8-users
accessor* ofc.
Reply all
Reply to author
Forward
0 new messages