Is it required to grab v8::Locker before making v8::Function::Call?
<p>I'm using V8 to execute some custom javascript code, exposing <code>OnUpdate</code> function to JS world. Overall code works fine but currently I'm concerned about performance of below code - is it required to grab <code>v8::Locker</code> for executing any user defined function? <code>Instruments.app</code> shows code here spends way too much time in <code>v8::Locker</code> constructor and destructor - </p>

<p><a href="https://i.stack.imgur.com/sFVc6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sFVc6.png" alt="v8 profile"></a>
</p>

<p>90 ms (in actual code execution) vs ~4000ms (by <code>Locker</code> &amp; <code>~Locker</code>) - this is absurd and I feel I might be doing something wrong.</p>

<p>So my basic question is it really necessary to grab <code>v8::Locker</code> to execute a <code>v8::Function::Call</code>? In current state if I comment out <code>v8::Locker</code>I get below error message:</p>

<pre><code># Fatal error in HandleScope::HandleScope
# Entering the V8 API without proper locking in place
</code></pre>

<p>Code snippet:</p>

<pre><code>int Bucket::send_doc_update_bucket(const char *msg) {
    Locker locker(GetIsolate());
    Isolate::Scope isolate_scope(GetIsolate());
    HandleScope handle_scope(GetIsolate());

    Local&lt;Context&gt; context = Local&lt;Context&gt;::New(GetIsolate(), context_);
    Context::Scope context_scope(context);

    TryCatch try_catch;

    Local&lt;Value&gt; args[1];
    args[0] = String::NewFromUtf8(GetIsolate(), msg);

    assert(!try_catch.HasCaught());

    Handle&lt;Value&gt; val;
    if(!context-&gt;Global()-&gt;Get(context,
                               createUtf8String(GetIsolate(),
                                                "OnUpdate")).ToLocal(&amp;val) ||
      !val-&gt;IsFunction()) {
          return 3;
    }

    Handle&lt;Function&gt; on_doc_update = Handle&lt;Function&gt;::Cast(val);
    on_doc_update-&gt;Call(context, context-&gt;Global(), 1, args);

    if (try_catch.HasCaught()) {
        //w-&gt;last_exception = ExceptionString(GetIsolate(), &amp;try_catch);
        return 2;
    }

    return 0;
 }
</code></pre>