re: ELI5: v8 Isolates and Contexts VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION
 

@zee thank you for this very well crafted response.

My understanding was that an Isolate, to put this in Unix terms, would be an in-process thread, and that you can spawn as many Isolates as you need inside a true Unix process. But when viewed that way, I am not sure where Contexts fit, since you can have many Context inside an Isolate. A lot of this thinking came from research I did, after posting this question.

If I have a program with v8 embedded inside of it, running that program would create a true process in Unix, but inside that process my program might spawn many Isolates that can run in parallel, within the same unix process. These Isolates might then spawn multiple Contexts within an Isolate. Isolates can be run in parallel, but Contexts can not be parallelized within an Isolate, but they can share memory. I guess I'm just not sure what having multiple Contexts in an Isolate will give you?

Does this explanation jive with how you understand v8?

I very much appreciate your response and looking forward to more discussion!

 

Hmm, I wasn't aware that a Context is a singleton within an Isolate, but I guess that makes sense that they're a mechanism for sharing data across code in an isolate.

Maybe that's how Chrome winds up sharing state between web pages and web workers on the page?

@Zee Maybe they aren't? That's just my understanding which could certainly be incorrect. It's difficult to find info outside of the limited description in the v8 API docs of both classes. It seems NodeJS briefly supported Isolates, but no longer, and no Chrome or v8 documentation that I've seen really discusses them in detail even though they seem to be a really huge idea inside v8.

Here is some documentation I found, but it was surprisingly hard to locate!!
v8docs.nodesource.com/node-10.6/d5...
v8docs.nodesource.com/node-10.6/df...

I wonder if this is an instance where a more concrete example of the use case you're trying to apply with Isolates or Contexts would be helpful?

I'm definitely tilting towards the edge of my understanding and competence though, but hopefully I can at least quack a bit and the rubber duck will go on :)

No particular use-case at the moment, but I was reading more about the Cloudflare Worker runtime which explains how they are using v8 Isolates to create sandboxed serverless workers. Some details here: blog.cloudflare.com/serverless-per...

@Zee i found some additional examples in NodeJS source, using Isolates in the experimental Workers API: github.com/nodejs/node/blob/master...

some more details provided by a member of the v8 team, Yang Guo.

twitter.com/hashseed/status/106875...

Nice, that feels like it clears things up a bit more!

code of conduct - report abuse