Thanks! it worked. although i did had issues with the api returning const 
but the ScriptCompiler::source api requiring non-const cache.

On Monday, November 13, 2017 at 11:01:49 AM UTC+2, Ben Noordhuis wrote:
>
> On Mon, Nov 13, 2017 at 7:02 AM,  <fkp...@gmail.com <javascript:>> wrote: 
> > hi, 
> > i have multi thread program with thread per isolate and context which 
> each 
> > runs the same script. 
> > 
> > Since they all compile same script - I'd like to use the compiler to 
> create 
> > cache and distribute it between them. 
> > Currently i get a crash when I get to the step of actually running the 
> > script: 
> > 
> > Can I share code cache (example below) between isolates?  and script 
> > compilations? 
> > 
> > code example: 
> > 
> > 
> > v8::TryCatch try_catch(thread_component_->thread_isolate); 
> > v8::ScriptOrigin script_origin(v8::String::NewFromUtf8( 
> >         thread_isolate, 
> >         fileName)); 
> > 
> > const v8::Local<v8::String> raw_script(v8::String::NewFromUtf8( 
> > thread_isolate,  file_code)); 
> > 
> > v8::MaybeLocal<v8::UnboundScript> unbound_script; 
> > 
> > v8::ScriptCompiler::Source* script_cache = 
> > script_cache_manager->GetScriptCache(fileName); 
> >     if (script_cache == nullptr) { 
> >         script_cache = new v8::ScriptCompiler::Sourceraw_script, 
> > script_origin); 
> >         unbound_script = 
> v8::ScriptCompiler::CompileUnboundScript(isolate, 
> >             script_cache, v8::ScriptCompiler::kProduceCodeCache); 
> >         script_cache = script_cache_manager->AddScriptCache(fileName, 
> > script_cache); 
> >     } else { 
> >         unbound_script = 
> v8::ScriptCompiler::CompileUnboundScript(isolate, 
> >             script_cache, v8::ScriptCompiler::kConsumeCodeCache); 
> >     } 
> > 
> >     v8::Local<v8::Script> script = 
> > unbound_script.ToLocalChecked()->BindToCurrentContext(); 
> > 
> > 
> >     if (script.IsEmpty() || try_catch.HasCaught()) { 
> > 
> > 
> thread_component_->thread_isolate->ThrowException(try_catch.Exception()); 
> >         return; 
> >     } 
> > 
> >     v8::MaybeLocal<v8::Value> result(script->Run( 
> >         isolate_context)); 
> > 
> >     if (result.IsEmpty() || try_catch.HasCaught()) { 
> > 
> > 
> thread_component_->thread_isolate->ThrowException(try_catch.Exception()); 
> >         return; 
> >     } 
> > 
> > are there any suggestions for other optimazations i can do accross 
> isolates? 
>
> You can share scripts across isolates.  Invoke CompileUnboundScript() 
> with the kProduceCodeCache flag and cache the result of 
> Source::GetCachedData() afterwards. 
>
> On the next run, pass the cached data to the Source constructor and 
> pass that along with the kConsumeCodeCache flag to 
> CompileUnboundScript(). 
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to