rusty_racer 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +50 -0
- data/ext/rusty_racer/Cargo.toml +7 -2
- data/ext/rusty_racer/src/lib.rs +23 -2228
- data/ext/rusty_racer/src/marshal.rs +798 -0
- data/ext/rusty_racer/src/ops.rs +1061 -0
- data/ext/rusty_racer/src/stack.rs +292 -0
- data/ext/rusty_racer/src/watchdog.rs +226 -0
- data/lib/rusty_racer/execjs.rb +118 -0
- data/lib/rusty_racer/version.rb +1 -1
- metadata +13 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b0b742605170382bce639eaa6c8acd1917f6ed4e6f8a5d4f83d40701ffb14b25
|
|
4
|
+
data.tar.gz: ce873858c2a28e9903ca9abec1cc72e061f3561f1cf2c8d5b0ff3694d613ec55
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e3960b00b14c62813d731ee85c8f41cca8f04a0ff7657446f205dda2f24c5e11fd07b00da000b1d7be503bb00f083cf389f3736fac8d6344343a6ec26a3a11e
|
|
7
|
+
data.tar.gz: 3ee0d6217b064b70362a7e2475e5db840a0b613922f91a418d3548464066ea1824d1c073870e5d9d6da4cdc351fa481e490d667520123675f2b7d730a926d23e
|
data/README.md
CHANGED
|
@@ -9,6 +9,34 @@ Embed [V8](https://v8.dev/) in Ruby, built on [rusty_v8](https://crates.io/crate
|
|
|
9
9
|
> is **thread-confined**: every operation must happen on that owner thread, or it
|
|
10
10
|
> raises. `Isolate#terminate` is the exception — it is safe from any thread.
|
|
11
11
|
|
|
12
|
+
## Highlights
|
|
13
|
+
|
|
14
|
+
- **ES modules**, including dynamic `import()` with an embedder-owned resolver —
|
|
15
|
+
not just classic scripts.
|
|
16
|
+
- **Faithful value marshalling**: `BigInt`, `Date`, `Map`, `Set`, typed binary
|
|
17
|
+
(`Uint8Array`/`ArrayBuffer` ↔ binary `String`), and shared/cyclic object
|
|
18
|
+
graphs all round-trip — no lossy JSON hop.
|
|
19
|
+
- **In-thread execution** — V8 runs on the calling Ruby thread, with no dedicated
|
|
20
|
+
V8 thread and no per-op thread hop; fast when you run many small ops.
|
|
21
|
+
- **Drop-in [ExecJS](#execjs) runtime** — any ExecJS consumer switches with no
|
|
22
|
+
code change.
|
|
23
|
+
- **Snapshots, realms (`Context`s), host callbacks, and a bytecode cache.**
|
|
24
|
+
- **Precompiled gems** bundle V8 for Linux/macOS × Ruby 3.3–4.0 — no V8 build,
|
|
25
|
+
no Rust toolchain.
|
|
26
|
+
|
|
27
|
+
### Compared to mini_racer
|
|
28
|
+
|
|
29
|
+
[mini_racer](https://github.com/rubyjs/mini_racer) is the mature, widely-deployed
|
|
30
|
+
incumbent — if you want a battle-tested binding or **Windows** support, reach for
|
|
31
|
+
it. rusty_racer differs where it counts for some workloads: native **ES modules +
|
|
32
|
+
dynamic import** (mini_racer is eval/classic-script oriented); **richer
|
|
33
|
+
marshalling** (the types above round-trip natively instead of through a
|
|
34
|
+
JSON-shaped projection); and **in-thread execution** with no per-op thread hop,
|
|
35
|
+
which is faster for overhead-dominated workloads (lots of tiny `eval`/`call`) and
|
|
36
|
+
at parity once the per-op JS work dominates. It is also younger and
|
|
37
|
+
**experimental** — fewer miles, no Windows yet, no per-isolate memory cap. Parity
|
|
38
|
+
with mini_racer is not a goal; the overlap is convergent evolution, not a port.
|
|
39
|
+
|
|
12
40
|
## What it can do
|
|
13
41
|
|
|
14
42
|
Names follow V8's: an `Isolate` is the VM; it hands out `Context`s (v8::Context,
|
|
@@ -122,6 +150,28 @@ warm isolate — a per-visit reset that avoids rebuilding the VM. Its contract:
|
|
|
122
150
|
suspended on the V8 stack (e.g. resetting a realm from inside one of its own
|
|
123
151
|
host fns).
|
|
124
152
|
|
|
153
|
+
## ExecJS
|
|
154
|
+
|
|
155
|
+
rusty_racer ships an optional [ExecJS](https://github.com/rails/execjs) runtime,
|
|
156
|
+
so any ExecJS consumer (asset pipelines, CoffeeScript/Babel/Uglify wrappers, …)
|
|
157
|
+
can run on V8-in-Ruby with no code change:
|
|
158
|
+
|
|
159
|
+
```ruby
|
|
160
|
+
require "rusty_racer/execjs"
|
|
161
|
+
ExecJS.runtime = RustyRacer::ExecJSRuntime.new
|
|
162
|
+
|
|
163
|
+
ExecJS.eval("'foo bar'.toUpperCase()") # => "FOO BAR"
|
|
164
|
+
ctx = ExecJS.compile("function add(a, b) { return a + b }")
|
|
165
|
+
ctx.call("add", 1, 2) # => 3
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The adapter is **opt-in** — `rusty_racer` never requires `execjs` itself, so it
|
|
169
|
+
stays a non-dependency; `require "rusty_racer/execjs"` pulls it in only when you
|
|
170
|
+
ask. Values cross with ExecJS's JSON semantics (functions and `undefined` drop
|
|
171
|
+
out, Dates become ISO strings), matching what ExecJS's external runtimes give, so
|
|
172
|
+
results are identical whatever runtime a library picked. The integration is
|
|
173
|
+
verified against ExecJS's own runtime contract suite (`test/execjs_test.rb`).
|
|
174
|
+
|
|
125
175
|
## Threading
|
|
126
176
|
|
|
127
177
|
An `Isolate` runs V8 **in-thread** on the Ruby thread that created it, and is
|
data/ext/rusty_racer/Cargo.toml
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# libv8-rusty needed under the cibuildgem native-per-platform model).
|
|
5
5
|
[package]
|
|
6
6
|
name = "rusty_racer"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
edition = "2021"
|
|
9
9
|
publish = false
|
|
10
10
|
|
|
@@ -17,7 +17,12 @@ crate-type = ["cdylib"]
|
|
|
17
17
|
# to root the owner thread).
|
|
18
18
|
magnus = { version = "0.8", features = ["rb-sys"] }
|
|
19
19
|
rb-sys = "0.9"
|
|
20
|
-
|
|
20
|
+
# simdutf: SIMD-accelerated UTF-8/UTF-16 transcoding in rusty_v8's String
|
|
21
|
+
# conversion (to_rust_string_lossy etc.), the path every V8->Ruby string crosses.
|
|
22
|
+
# ~6-8x faster marshalling for non-ASCII results (measured); ASCII is unaffected.
|
|
23
|
+
# Needs the linked archive built with rusty_v8_enable_simdutf=true (libv8-rusty.yml
|
|
24
|
+
# for linux; the v8 crate auto-fetches Deno's _simdutf prebuilt on macOS).
|
|
25
|
+
v8 = { version = "150.0.0", features = ["simdutf"] }
|
|
21
26
|
# pthread stack-bounds query, to set V8's stack limit per op relative to the
|
|
22
27
|
# current native thread (in-thread V8 runs on the Ruby thread's stack).
|
|
23
28
|
libc = "0.2"
|