Module: Dommy::Js::Quickjs::ScriptCache

Defined in:
lib/dommy/js/quickjs/script_cache.rb

Overview

A process-global cache of compiled external-script bytecode, keyed by URL. Vendored bundles (turbo.umd.js, stimulus.umd.js, application.js, …) are identical across page loads but otherwise re-parsed on every fresh VM; compiling each once and running the bytecode per VM removes that repeated parse cost (the bundles are hundreds of KB).

Keyed by URL: an asset URL maps 1:1 to its content (Propshaft / Sprockets digest-stamp it; test fixtures are stable within a process).

The bridge’s built-in runtime bundles (host_runtime.js, observable_runtime.js) use a separate cache in Backend#run_bundle, so an external-script count here stays uncontaminated by engine internals.

Class Method Summary collapse

Class Method Details

.clearObject



28
29
30
# File 'lib/dommy/js/quickjs/script_cache.rb', line 28

def clear
  @mutex.synchronize { @cache.clear }
end

.compiled(url, source) ⇒ Object

The compiled bytecode for ‘url`, compiling `source` on first use.



24
25
26
# File 'lib/dommy/js/quickjs/script_cache.rb', line 24

def compiled(url, source)
  @mutex.synchronize { @cache[url] ||= Backend.compile(source, filename: url.to_s) }
end

.sizeObject



32
# File 'lib/dommy/js/quickjs/script_cache.rb', line 32

def size = @cache.size