You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-38Lines changed: 7 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -206,58 +206,27 @@ context.eval("counter")
206
206
# => 1
207
207
```
208
208
209
-
### Shared isolates
209
+
### Garbage collection
210
210
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:
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:
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
246
215
247
216
# do stuff with that context...
248
217
249
218
# give up to 100ms for V8 garbage collection
250
-
isolate.idle_notification(100)
219
+
context.idle_notification(100)
251
220
252
221
# force V8 to perform a full GC
253
-
isolate.low_memory_notification
222
+
context.low_memory_notification
254
223
```
255
224
256
225
This can come in handy to force V8 GC runs for example in between requests if you use MiniRacer on a web application.
257
226
258
227
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.`
259
228
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.
261
230
262
231
### V8 Runtime flags
263
232
@@ -301,7 +270,7 @@ Please refer to http://node.green/ as a reference on other harmony features.
301
270
302
271
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).
303
272
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 contextor a snapshot), otherwise an exception will be thrown.
0 commit comments