On Thursday, April 12, 2012 9:43:37 PM UTC+8, Stephan Beal wrote:
>
> On Thu, Apr 12, 2012 at 3:39 PM, Michael Schwartz <[email protected]>wrote:
>
>> In my case, I really coded for speed. It got to the point in HTTP
>> serving where an extra syscall or string copy was killing my
>> requests/second performance by 10%. That's like from 45,000
>> requests/second down to 40,000.
>>
>
> Obviously, my approach (lazy/convenient) is not appropriate there :).
>
> I'm even questioning whether I even need HandleScope at all. Every
>> nanosecond counts! ;-)
>>
>
> i gave up handle scopes a long time ago - 99% of my code is called "from
> v8", so i've never needed them. i didn't give them up for performance, but
> because i just kept seeing weird crashes very often which went away when i
> removed the handle scopes. So my vote is: don't feel bad about getting rid
> of them. Funcs called "from v8" implicitly have a scope. Only funcs which
> use v8 and are called from native code (possibly) need a handle scope. At
> least that's my understanding based on past threads on this list.
>
>
Hello,
I'm new, so can someone please check my logic here...
So if I understand correctly:
* there is no real difference between Local<> and Handle<>, both need a
HandleScope. Local<> does not clean up after itself like a smartpointer.
* the reason that you may not need a HandleScope is if the function caller
(or its caller, etc etc) has already created a HandleScope.
and:
* if you do NOT make a HandleScope, then any objects that you created in
your function will not be released until much later.
so for example, if your function is called by v8 like so:
void some_v8_core_function()
{
HandleScope scope;
vector<> handles;
for (int i = 0; i < a billion; ++i)
handles.push_back(your_function(whatever));
// v8 keeps the handles it got from your_function
}
then your function's handles won't be cleaned up until after the loop has
run a billion times. So if your_function looks like this:
void your_function( v8::Args whatever )
{
// note - no handlescope
Local<Value> val = v8::String::New(whatnot);
// do stuff
return v8::Number::New(something);
}
then there will be a billion strings created and NOT released until the
loop has finished.
the Numbers will be eventually kept by v8 to do things, but the Strings
will all be cleaned up.
So the difference is,
* with handlescope in your_function(): cleans up (ie release) along the way,
* without handlescope in your_function: does not release until an assumed
scope further up the call chain is closed.
And we have no real way of knowing how v8 is calling our functions.
Are they always wrapping calls to our functions with HandleScope? without
looking at the code, I'd say no, as there would be a performance penalty
for being cautious.
Is that how things work?
cheers
Paul
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users