Skip to content

Commit 0017e57

Browse files
authored
Remove isolate references from README (#331)
Isolates were removed in commit 4e96a64 ("Run V8 on separate thread") by yours truly.
1 parent 394980b commit 0017e57

File tree

1 file changed

+7
-38
lines changed

1 file changed

+7
-38
lines changed

README.md

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -206,58 +206,27 @@ context.eval("counter")
206206
# => 1
207207
```
208208

209-
### Shared isolates
209+
### Garbage collection
210210

211-
By default, MiniRacer's contexts each have their own isolate (V8 runtime). For efficiency, it is possible to re-use an isolate across contexts:
211+
Re-using the same context over and over again means V8's garbage collector will have to run to clean it up every now and then; it's possible to trigger a _blocking_ V8 GC run inside your context by running the `idle_notification` method on it, which takes a single argument: the amount of time (in milliseconds) that V8 should use at most for garbage collecting:
212212

213213
```ruby
214-
isolate = MiniRacer::Isolate.new
215-
216-
context1 = MiniRacer::Context.new(isolate: isolate)
217-
context2 = MiniRacer::Context.new(isolate: isolate)
218-
219-
context1.isolate == context2.isolate
220-
# => true
221-
```
222-
223-
The main benefit of this is avoiding creating/destroying isolates when not needed (for example if you use a lot of contexts).
224-
225-
The caveat with this is that a given isolate can only execute one context at a time, so don't share isolates across contexts that you want to run concurrently.
226-
227-
Also, note that if you want to use shared isolates together with snapshots, you need to first create an isolate with that snapshot, and then create contexts from that isolate:
228-
229-
```ruby
230-
snapshot = MiniRacer::Snapshot.new("function hello() { return 'world!'; }")
231-
232-
isolate = MiniRacer::Isolate.new(snapshot)
233-
234-
context = MiniRacer::Context.new(isolate: isolate)
235-
236-
context.eval("hello()")
237-
# => "world!"
238-
```
239-
240-
Re-using the same isolate over and over again means V8's garbage collector will have to run to clean it up every now and then; it's possible to trigger a _blocking_ V8 GC run inside your isolate by running the `idle_notification` method on it, which takes a single argument: the amount of time (in milliseconds) that V8 should use at most for garbage collecting:
241-
242-
```ruby
243-
isolate = MiniRacer::Isolate.new
244-
245-
context = MiniRacer::Context.new(isolate: isolate)
214+
context = MiniRacer::Context.new
246215

247216
# do stuff with that context...
248217

249218
# give up to 100ms for V8 garbage collection
250-
isolate.idle_notification(100)
219+
context.idle_notification(100)
251220

252221
# force V8 to perform a full GC
253-
isolate.low_memory_notification
222+
context.low_memory_notification
254223
```
255224

256225
This can come in handy to force V8 GC runs for example in between requests if you use MiniRacer on a web application.
257226

258227
Note that this method maps directly to [`v8::Isolate::IdleNotification`](http://bespin.cz/~ondras/html/classv8_1_1Isolate.html#aea16cbb2e351de9a3ae7be2b7cb48297), and that in particular its return value is the same (true if there is no further garbage to collect, false otherwise) and the same caveats apply, in particular that `there is no guarantee that the [call will return] within the time limit.`
259228

260-
Additionally you may automate this process on a context by defining it with `MiniRacer::Content.new(ensure_gc_after_idle: 1000)`. Using this will ensure V8 will run a full GC using `context.isolate.low_memory_notification` 1 second after the last eval on the context. Low memory notification is both slower and more aggressive than an idle_notification and will ensure long living isolates use minimal amounts of memory.
229+
Additionally you may automate this process on a context by defining it with `MiniRacer::Context.new(ensure_gc_after_idle: 1000)`. Using this will ensure V8 will run a full GC using `context.low_memory_notification` 1 second after the last eval on the context. Low memory notification is both slower and more aggressive than an idle_notification and will ensure long living contexts use minimal amounts of memory.
261230

262231
### V8 Runtime flags
263232

@@ -301,7 +270,7 @@ Please refer to http://node.green/ as a reference on other harmony features.
301270

302271
A list of all V8 runtime flags can be found using `node --v8-options`, or else by perusing [the V8 source code for flags (make sure to use the right version of V8)](https://github.com/v8/v8/blob/master/src/flags/flag-definitions.h).
303272

304-
Note that runtime flags must be set before any other operation (e.g. creating a context, a snapshot or an isolate), otherwise an exception will be thrown.
273+
Note that runtime flags must be set before any other operation (e.g. creating a context or a snapshot), otherwise an exception will be thrown.
305274

306275
Flags:
307276

0 commit comments

Comments
 (0)