mini_racer 0.2.11 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/README.md +5 -0
- data/ext/mini_racer_extension/mini_racer_extension.cc +12 -0
- data/lib/mini_racer.rb +44 -2
- data/lib/mini_racer/version.rb +1 -1
- data/mini_racer.gemspec +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35ced47bf0cd66e605b6bd14005c23381b9fa42e438b0ab45a3c99414d107634
|
4
|
+
data.tar.gz: '02968be5850b866d1c399995cb6d942dc826730447524df008f604035449050e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c4fc5f71bcfddd5d58f5b0ae0f68e4b59067005362afbf29f096752f63fab9ea0d0526f2ba02d5a85f89976e607eae395c3714b6186282a6bce19217ae86ec0
|
7
|
+
data.tar.gz: 3d6268a03f472c01fa68278e4349c18b270765a8e831b020286a929b0fd0f2a1422b2c0c11432a33a348ec28044a38acdcd55d4cff93b436acc2fbed07ddfdf8
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
- 15-05-2020
|
2
|
+
|
3
|
+
- 0.2.12
|
4
|
+
|
5
|
+
- FEATURE: isolate.low_memory_notification which can force a full GC
|
6
|
+
- FEATURE: MiniRacer::Context.new(ensure_gc_after_idle: 2) - to force full GC 2 seconds after context is idle, this allows you to conserve memory on isolates
|
7
|
+
|
1
8
|
- 14-05-2020
|
2
9
|
|
3
10
|
- 0.2.11
|
data/README.md
CHANGED
@@ -230,12 +230,17 @@ context = MiniRacer::Context.new(isolate: isolate)
|
|
230
230
|
# give up to 100ms for V8 garbage collection
|
231
231
|
isolate.idle_notification(100)
|
232
232
|
|
233
|
+
# force V8 to perform a full GC
|
234
|
+
isolate.low_memory_notification
|
235
|
+
|
233
236
|
```
|
234
237
|
|
235
238
|
This can come in handy to force V8 GC runs for example in between requests if you use MiniRacer on a web application.
|
236
239
|
|
237
240
|
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.`
|
238
241
|
|
242
|
+
Additionally you may automate this process on a context by defining it with `MiniRacer::Content.new(ensure_gc_after_idle: 1)`. 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.
|
243
|
+
|
239
244
|
### V8 Runtime flags
|
240
245
|
|
241
246
|
It is possible to set V8 Runtime flags:
|
@@ -769,6 +769,16 @@ static VALUE rb_isolate_idle_notification(VALUE self, VALUE idle_time_in_ms) {
|
|
769
769
|
return isolate_info->isolate->IdleNotificationDeadline(now + duration) ? Qtrue : Qfalse;
|
770
770
|
}
|
771
771
|
|
772
|
+
static VALUE rb_isolate_low_memory_notification(VALUE self) {
|
773
|
+
IsolateInfo* isolate_info;
|
774
|
+
Data_Get_Struct(self, IsolateInfo, isolate_info);
|
775
|
+
|
776
|
+
if (current_platform == NULL) return Qfalse;
|
777
|
+
|
778
|
+
isolate_info->isolate->LowMemoryNotification();
|
779
|
+
return Qnil;
|
780
|
+
}
|
781
|
+
|
772
782
|
static VALUE rb_context_init_unsafe(VALUE self, VALUE isolate, VALUE snap) {
|
773
783
|
ContextInfo* context_info;
|
774
784
|
Data_Get_Struct(self, ContextInfo, context_info);
|
@@ -1657,6 +1667,8 @@ extern "C" {
|
|
1657
1667
|
rb_define_private_method(rb_cSnapshot, "load", (VALUE(*)(...))&rb_snapshot_load, 1);
|
1658
1668
|
|
1659
1669
|
rb_define_method(rb_cIsolate, "idle_notification", (VALUE(*)(...))&rb_isolate_idle_notification, 1);
|
1670
|
+
rb_define_method(rb_cIsolate, "low_memory_notification", (VALUE(*)(...))&rb_isolate_low_memory_notification, 0);
|
1671
|
+
|
1660
1672
|
rb_define_private_method(rb_cIsolate, "init_with_snapshot",(VALUE(*)(...))&rb_isolate_init_with_snapshot, 1);
|
1661
1673
|
|
1662
1674
|
rb_define_singleton_method(rb_cPlatform, "set_flag_as_str!", (VALUE(*)(...))&rb_platform_set_flag_as_str, 1);
|
data/lib/mini_racer.rb
CHANGED
@@ -145,6 +145,15 @@ module MiniRacer
|
|
145
145
|
end
|
146
146
|
# false signals it should be fetched if requested
|
147
147
|
@isolate = options[:isolate] || false
|
148
|
+
|
149
|
+
@ensure_gc_after_idle = options[:ensure_gc_after_idle]
|
150
|
+
|
151
|
+
if @ensure_gc_after_idle
|
152
|
+
@last_eval = nil
|
153
|
+
@ensure_gc_thread = nil
|
154
|
+
@ensure_gc_mutex = Mutex.new
|
155
|
+
end
|
156
|
+
|
148
157
|
@disposed = false
|
149
158
|
|
150
159
|
@callback_mutex = Mutex.new
|
@@ -203,6 +212,7 @@ module MiniRacer
|
|
203
212
|
end
|
204
213
|
ensure
|
205
214
|
@eval_thread = nil
|
215
|
+
ensure_gc_thread if @ensure_gc_after_idle
|
206
216
|
end
|
207
217
|
|
208
218
|
def call(function_name, *arguments)
|
@@ -216,15 +226,17 @@ module MiniRacer
|
|
216
226
|
end
|
217
227
|
ensure
|
218
228
|
@eval_thread = nil
|
229
|
+
ensure_gc_thread if @ensure_gc_after_idle
|
219
230
|
end
|
220
231
|
|
221
232
|
def dispose
|
222
233
|
return if @disposed
|
223
234
|
isolate_mutex.synchronize do
|
235
|
+
return if @disposed
|
224
236
|
dispose_unsafe
|
237
|
+
@disposed = true
|
238
|
+
@isolate = nil # allow it to be garbage collected, if set
|
225
239
|
end
|
226
|
-
@disposed = true
|
227
|
-
@isolate = nil # allow it to be garbage collected, if set
|
228
240
|
end
|
229
241
|
|
230
242
|
|
@@ -273,6 +285,36 @@ module MiniRacer
|
|
273
285
|
|
274
286
|
private
|
275
287
|
|
288
|
+
def ensure_gc_thread
|
289
|
+
@last_eval = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
290
|
+
@ensure_gc_mutex.synchronize do
|
291
|
+
@ensure_gc_thread = nil if !@ensure_gc_thread&.alive?
|
292
|
+
@ensure_gc_thread ||= Thread.new do
|
293
|
+
done = false
|
294
|
+
while !done
|
295
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
296
|
+
|
297
|
+
if @disposed
|
298
|
+
@ensure_gc_thread = nil
|
299
|
+
break
|
300
|
+
end
|
301
|
+
|
302
|
+
if @ensure_gc_after_idle < now - @last_eval
|
303
|
+
@ensure_gc_mutex.synchronize do
|
304
|
+
isolate_mutex.synchronize do
|
305
|
+
# extra 50ms to make sure that we really have enough time
|
306
|
+
isolate.low_memory_notification if !@disposed
|
307
|
+
@ensure_gc_thread = nil
|
308
|
+
done = true
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
sleep @ensure_gc_after_idle if !done
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
276
318
|
def stop_attached
|
277
319
|
@callback_mutex.synchronize{
|
278
320
|
if @callback_running
|
data/lib/mini_racer/version.rb
CHANGED
data/mini_racer.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
29
|
spec.add_development_dependency "bundler"
|
30
|
-
spec.add_development_dependency "rake", "
|
30
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
31
31
|
spec.add_development_dependency "minitest", "~> 5.0"
|
32
32
|
spec.add_development_dependency "rake-compiler"
|
33
33
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_racer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,9 +108,9 @@ licenses:
|
|
108
108
|
- MIT
|
109
109
|
metadata:
|
110
110
|
bug_tracker_uri: https://github.com/discourse/mini_racer/issues
|
111
|
-
changelog_uri: https://github.com/discourse/mini_racer/blob/v0.2.
|
112
|
-
documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.2.
|
113
|
-
source_code_uri: https://github.com/discourse/mini_racer/tree/v0.2.
|
111
|
+
changelog_uri: https://github.com/discourse/mini_racer/blob/v0.2.12/CHANGELOG
|
112
|
+
documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.2.12
|
113
|
+
source_code_uri: https://github.com/discourse/mini_racer/tree/v0.2.12
|
114
114
|
post_install_message:
|
115
115
|
rdoc_options: []
|
116
116
|
require_paths:
|