Isolates and threads

Apr 12, 2012 at 3:51 AM

Kaniga posted patch 11864 and wrote:

Isolates were created with every context creation, which is catastrophic for performance when creating many execution contexts.
Instead, they should be created only once per thread and destroyed on thread termination.

Unfortunately I don't think this will always work.  If you created two JavascriptContexts using one thread and then used them on multiple worker threads, then they would share a single Isolate and would crash.

I think this project should be more idiot proof than that.

As an alternative, we could have an overloaded JavascriptContext constructor that allows the user to supply his own Isolate (wrapped in a CLR object).  Thoughts?

Apr 27, 2012 at 9:57 AM

That would require the developer to "know" too much of the inner workings of the V8 engine.

I suppose a more idiot proof API (better abstraction / loosely coupled)

is to have a boolean argument in the constructor to state whether the context may be used in multiple threads:

If false - then the context will use a per-thread global isolate

If true - then the context will have its own isolate