PERF: ensure we run full GC on contexts
Prior to this change we would never clear memory from contexts and rely on V8 reacting to pressure This could lead to bloating of PrettyText and Transpiler contexts This optimisations ensures that we will clear memory 2 seconds after the last eval on the context
This commit is contained in:
parent
0cbaa8d813
commit
4601833e4e
|
@ -188,7 +188,7 @@ GEM
|
||||||
method_source (1.0.0)
|
method_source (1.0.0)
|
||||||
mini_mime (1.0.2)
|
mini_mime (1.0.2)
|
||||||
mini_portile2 (2.4.0)
|
mini_portile2 (2.4.0)
|
||||||
mini_racer (0.2.11)
|
mini_racer (0.2.14)
|
||||||
libv8 (> 7.3)
|
libv8 (> 7.3)
|
||||||
mini_scheduler (0.12.2)
|
mini_scheduler (0.12.2)
|
||||||
sidekiq
|
sidekiq
|
||||||
|
|
|
@ -79,7 +79,7 @@ class DiscourseJsProcessor
|
||||||
|
|
||||||
def self.create_new_context
|
def self.create_new_context
|
||||||
# timeout any eval that takes longer than 15 seconds
|
# timeout any eval that takes longer than 15 seconds
|
||||||
ctx = MiniRacer::Context.new(timeout: 15000)
|
ctx = MiniRacer::Context.new(timeout: 15000, ensure_gc_after_idle: 2000)
|
||||||
ctx.eval("var self = this; #{File.read("#{Rails.root}/vendor/assets/javascripts/babel.js")}")
|
ctx.eval("var self = this; #{File.read("#{Rails.root}/vendor/assets/javascripts/babel.js")}")
|
||||||
ctx.eval(File.read(Ember::Source.bundled_path_for('ember-template-compiler.js')))
|
ctx.eval(File.read(Ember::Source.bundled_path_for('ember-template-compiler.js')))
|
||||||
ctx.eval("module = {}; exports = {};")
|
ctx.eval("module = {}; exports = {};")
|
||||||
|
|
|
@ -282,7 +282,7 @@ module JsLocaleHelper
|
||||||
def self.with_context
|
def self.with_context
|
||||||
@mutex.synchronize do
|
@mutex.synchronize do
|
||||||
yield @ctx ||= begin
|
yield @ctx ||= begin
|
||||||
ctx = MiniRacer::Context.new(timeout: 15000)
|
ctx = MiniRacer::Context.new(timeout: 15000, ensure_gc_after_idle: 2000)
|
||||||
ctx.load("#{Rails.root}/lib/javascripts/messageformat.js")
|
ctx.load("#{Rails.root}/lib/javascripts/messageformat.js")
|
||||||
ctx
|
ctx
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,7 +65,7 @@ module PrettyText
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_es6_context
|
def self.create_es6_context
|
||||||
ctx = MiniRacer::Context.new(timeout: 25000)
|
ctx = MiniRacer::Context.new(timeout: 25000, ensure_gc_after_idle: 2000)
|
||||||
|
|
||||||
ctx.eval("window = {}; window.devicePixelRatio = 2;") # hack to make code think stuff is retina
|
ctx.eval("window = {}; window.devicePixelRatio = 2;") # hack to make code think stuff is retina
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue