On Mon, Jan 17, 2011 at 1:26 AM, Egor Egorov <[email protected]> wrote:
> I am writing a code that will parse a huge number of 32bit integers from a
> binary chunk and do some math I need.
> I coded it in JS (node.js 0.3.x with V8 3.x), and the calculations took
> about 1 minute. Then I rewrote the main cycle in C++ module to speed it u
> and it took... about 5 min. Here's a snippet of code that is running in C++
> context, something like that:
> HandleScope scope;
> Local<Array> js_result = Array::New();
> int i=0;
> for(i=0;i<size;i++) {
> int off=i*4;
> Local<Array> js_entry = Array::New();
> js_entry->Set(Integer::New(q), Number::New(ticks[off]));
> js_entry->Set(Integer::New(q+1), Number::New(ticks[off+3]));
> js_entry->Set(Integer::New(q+2), Number::New(ticks[off+2]));
> scope.Close(js_entry);
> js_result->Set(Number::New(i), js_entry);
> }
> return scope.Close(js_result);
>
> Does it mean that calls from C++ to create V8 JS objects are expensive?
> Integer::New() and so alike?
Maybe it just means that the JS code is fast? A transition from native
code into the VM runtime will always incur some overhead. A "huge
number" of these transitions may well be more expensive than the
comparatively trivial work you're performing.
What may or may not help:
* You may want to pre-size your Arrays correctly:
V8EXPORT static Local<Array> New(int length = 0);
* You can use
V8EXPORT bool Set(uint32_t index,
Handle<Value> value);
* You could re-design your structure to use three large arrays instead
of one array of three-element arrays. Maybe the
IndexedPropertiesToPixelData*/ExternalArray* familiy of methods could
help you, but I'm not familiar with them.
Matthias
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users