Class: Capybara::Simulated::QuickJSRuntime::VmPool
- Inherits:
-
Object
- Object
- Capybara::Simulated::QuickJSRuntime::VmPool
- Defined in:
- lib/capybara/simulated/quickjs_runtime.rb
Overview
Pre-warmed pool of bare Quickjs::VM instances. Quickjs::VM.new
with POLYFILL_INTL is ~140 ms (FormatJS locale tables + IANA TZ
bytecode); quickjs.rb #36 released the GVL during construction,
so warmer threads build in parallel with the main thread.
build_vm pops a pre-built VM and only pays for bridge replay +
host-fn attach (~30 ms) on the hot path.
Constant Summary collapse
- WARMER_COUNT =
4 warmers × ~140 ms ≈ 28 VMs/sec — covers sustained demand for shared-spec-shaped runs. CAPACITY buffers short bursts before warmers backfill.
4- CAPACITY =
6
Instance Method Summary collapse
- #checkout ⇒ Object
-
#initialize(vm_options) ⇒ VmPool
constructor
A new instance of VmPool.
-
#shutdown ⇒ Object
SizedQueue#close unblocks pushers + makes future pops return nil — necessary at process exit because a warmer mid-
VM.newhas the GVL released and would SEGV on interpreter teardown.
Constructor Details
#initialize(vm_options) ⇒ VmPool
Returns a new instance of VmPool.
82 83 84 85 86 87 88 |
# File 'lib/capybara/simulated/quickjs_runtime.rb', line 82 def initialize() @vm_options = @queue = SizedQueue.new(CAPACITY) @threads = WARMER_COUNT.times.map {|i| Thread.new { warmer_loop }.tap {|t| t.name = "csim-qjs-warmer-#{i}" } } end |
Instance Method Details
#checkout ⇒ Object
90 |
# File 'lib/capybara/simulated/quickjs_runtime.rb', line 90 def checkout = @queue.pop |
#shutdown ⇒ Object
SizedQueue#close unblocks pushers + makes future pops return
nil — necessary at process exit because a warmer mid-VM.new
has the GVL released and would SEGV on interpreter teardown.
95 96 97 98 |
# File 'lib/capybara/simulated/quickjs_runtime.rb', line 95 def shutdown @queue.close @threads.each {|t| t.join(2) } end |