1) the code snippet above is incorrect, you are closing HandleScope
several times.

HandleScope::Close is required when you want to pass ownership over
some value from current HandleScope to it's parent. It's a one-time
operation usually applied to function's return value. You don't need
HandleScope::Close if you are assigning value to a property.

2) It's a bit hard to say what's going on in this particular case
without seeing both JavaScript and C++ side but in general C++ code
like:

js_entry->Set(Integer::New(q), Number::New(ticks[off]));

will be slower than JS code like:

a[q] = ticks[offs];

(I assume that a and ticks are JS arrays and q and offs are integers).

C++ code requires a lot of calls while for JS V8 will emit nice
specialized native code.

--
Vyacheslav Egorov


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?
>
> --
> 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

Reply via email to