mini_racer_rs 1.0.1 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aeb35a422c03ec1f8366cc6794daefa2cbacd69d8e113c0e1cb1d369a274cf07
4
- data.tar.gz: e672b7b588ec4eb10e95317af8eea2a5d03aaf7340200b70c307f6a74e988606
3
+ metadata.gz: dfd3987a3aebfd95013e67e552b2041b991fd7b0da4933f98ae92335f7caa3a4
4
+ data.tar.gz: 51ccdf38b39ab3f33f771f3cf7fdbd7422bda16037e8bc026cfd64dc6fdfbdae
5
5
  SHA512:
6
- metadata.gz: 95f7422df0c8a5f74675fdcdcf9ba1d9e9c3e7278a67b1bd57a4964ee38a022570b2b968db0a3b81af8e6320b2d2bbb9d98489bdfd87b3a8f78edb5971a595f9
7
- data.tar.gz: 5288702eb114fe82c194a5071e15c99f36e6d2dbfb7c6541813074b89fb774a446dd84f4198c494306401a26cfda8932a082d8904f28bd468f01cda11bc29dcd
6
+ metadata.gz: ca5321d48ea8913f86d8966b6f475857d11b962c1f109e15f049fed590a517233f2cc3772fad99a9ff189f110995d3b2a0268f54e9f90aa48fcdd3cc1ac2b916
7
+ data.tar.gz: 3c2a6c804148cfd0bdf198d5a63ef4b440d63c667d7468ab646e8b85b277eb15ec0fa26f5d9877f426c01427e8f841723cf31d00bec0ee546881c895d373c61b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.3](https://github.com/andymai/mini_racer_rs/compare/v1.0.2...v1.0.3) (2026-10-18)
4
+
5
+
6
+ ### Performance
7
+
8
+ * **decode:** intern hash keys, build each Hash at once, and transcode strings in one pass ([#87](https://github.com/andymai/mini_racer_rs/issues/87)) ([220bfe7](https://github.com/andymai/mini_racer_rs/commit/220bfe7e6a9c8fa5a38befefcb4995756c377944))
9
+
10
+ ## [1.0.2](https://github.com/andymai/mini_racer_rs/compare/v1.0.1...v1.0.2) (2026-10-18)
11
+
12
+
13
+ ### Performance
14
+
15
+ * **engine:** share one copy of a large repeated source across contexts ([#85](https://github.com/andymai/mini_racer_rs/issues/85)) ([9fe050a](https://github.com/andymai/mini_racer_rs/commit/9fe050a7a612314264e255f9bcc40ca146e93571))
16
+
3
17
  ## [1.0.1](https://github.com/andymai/mini_racer_rs/compare/v1.0.0...v1.0.1) (2026-10-18)
4
18
 
5
19
 
data/COMPATIBILITY.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  | Engine | Done | Planned | Deviation |
6
6
  |---|---|---|---|
7
- | CRuby | 54 | 0 | 25 |
7
+ | CRuby | 54 | 0 | 26 |
8
8
  | TruffleRuby | 58 | 0 | 0 |
9
9
 
10
10
  ## Surface
@@ -180,6 +180,12 @@ mini_racer_rs supports glibc Linux on x86_64 and aarch64, plus macOS on arm64 an
180
180
 
181
181
  Approved 2026-10-16.
182
182
 
183
+ ### `behavior:shared-source-heap-stats@ruby`
184
+
185
+ `Context#heap_stats` can report large source text differently from mini_racer 0.22.1. When a context evaluates a source of 1 MiB or more that the process has evaluated before under the same file name and startup snapshot, mini_racer_rs gives V8 one copy shared by every such context and held outside V8's heap. It reports that source in `:external_memory` and omits it from `:used_heap_size`. V8 counts the shared source by its length in characters, so two-byte text reports half its bytes. mini_racer 0.22.1 reports `:external_memory` as 0 and counts each context's own copy in `:used_heap_size`. JavaScript sees the same source text in both gems. Contexts using `max_memory:` and sources that are not valid UTF-8 retain individual copies. Setting `MINI_RACER_RS_CODE_CACHE=off` before creating the first context disables sharing and makes `heap_stats` count every source as mini_racer does.
186
+
187
+ Approved 2026-10-18.
188
+
183
189
  ### `behavior:snapshot-filter-context@ruby`
184
190
 
185
191
  mini_racer_rs returns the same filtered results from a snapshot-based context as from a context without a snapshot. In a context made from `MiniRacer::Snapshot.new("Object.getOwnPropertyDescriptors = () => ({})")`, `({a: 1, f() {}})` returns `{"a" => 1}`, and `[1, function() {}]` returns `[1]`. mini_racer 0.22.1 returns `nil` for both. Both gems copy results that V8 refuses to serialize as is through a filter in a separate safe context. mini_racer_rs keeps an untouched context in each snapshot blob and uses it for that filter, while mini_racer 0.22.1 builds the safe context from the snapshot, exposing the filter's built-ins to snapshot code. User code still sees the replacement in both gems: `Object.getOwnPropertyDescriptors({a: 1})` returns `{}`.
data/Cargo.lock CHANGED
@@ -458,7 +458,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
458
458
 
459
459
  [[package]]
460
460
  name = "mini_racer_engine"
461
- version = "1.0.1"
461
+ version = "1.0.3"
462
462
  dependencies = [
463
463
  "deno_core_icudata",
464
464
  "libc",
@@ -470,7 +470,7 @@ dependencies = [
470
470
 
471
471
  [[package]]
472
472
  name = "mini_racer_rs"
473
- version = "1.0.1"
473
+ version = "1.0.3"
474
474
  dependencies = [
475
475
  "magnus",
476
476
  "mini_racer_engine",
@@ -481,7 +481,7 @@ dependencies = [
481
481
 
482
482
  [[package]]
483
483
  name = "mini_racer_sync"
484
- version = "1.0.1"
484
+ version = "1.0.3"
485
485
  dependencies = [
486
486
  "loom",
487
487
  "thiserror",
@@ -489,7 +489,7 @@ dependencies = [
489
489
 
490
490
  [[package]]
491
491
  name = "mini_racer_wire"
492
- version = "1.0.1"
492
+ version = "1.0.3"
493
493
  dependencies = [
494
494
  "proptest",
495
495
  "thiserror",
data/Cargo.toml CHANGED
@@ -14,7 +14,7 @@ license = "MIT"
14
14
  publish = false
15
15
  repository = "https://github.com/andymai/mini_racer_rs"
16
16
  rust-version = "1.91"
17
- version = "1.0.1"
17
+ version = "1.0.3"
18
18
 
19
19
  [workspace.dependencies]
20
20
  deno_core_icudata = "=0.78.0"
data/README.md CHANGED
@@ -183,7 +183,7 @@ bundle exec ruby bench/run.rb --cpus 0-7
183
183
 
184
184
  | Engine | Done | Planned | Deviation |
185
185
  |---|---|---|---|
186
- | CRuby | 54 | 0 | 25 |
186
+ | CRuby | 54 | 0 | 26 |
187
187
  | TruffleRuby | 58 | 0 | 0 |
188
188
 
189
189
  See [COMPATIBILITY.md](COMPATIBILITY.md).
@@ -77,15 +77,26 @@ impl Drop for Building {
77
77
 
78
78
  /// How the runner compiles a large script.
79
79
  pub(crate) enum Plan {
80
- /// From source: a first sighting, a key being built elsewhere, a refused
81
- /// cache, or the cache is off.
82
- Compile,
80
+ /// From source: a first sighting or the cache is off, or with its key, a
81
+ /// key being built elsewhere or a refused cache.
82
+ Compile(Option<Key>),
83
83
  /// From source, then a cache made once the dispatch is over.
84
84
  Make(Building),
85
85
  /// From the entry, falling back to source if V8 refuses it.
86
86
  Consume(Arc<Entry>, Key),
87
87
  }
88
88
 
89
+ impl Plan {
90
+ /// The key of a script the process has seen before.
91
+ pub(crate) const fn key(&self) -> Option<&Key> {
92
+ match self {
93
+ Self::Compile(key) => key.as_ref(),
94
+ Self::Make(building) => Some(&building.key),
95
+ Self::Consume(_, key) => Some(key),
96
+ }
97
+ }
98
+ }
99
+
89
100
  impl CodeCache {
90
101
  pub(crate) fn plan(
91
102
  &'static self,
@@ -94,7 +105,7 @@ impl CodeCache {
94
105
  snapshot: Option<u64>,
95
106
  ) -> Plan {
96
107
  if !enabled() {
97
- return Plan::Compile;
108
+ return Plan::Compile(None);
98
109
  }
99
110
  let sighting = self.sighting(filename, source, snapshot);
100
111
  let seen = touch(&self.sightings, sighting, MAX_SIGHTINGS);
@@ -103,7 +114,7 @@ impl CodeCache {
103
114
  .iter()
104
115
  .any(|entry| entry.key.sighting == sighting);
105
116
  if !seen && !cached {
106
- return Plan::Compile;
117
+ return Plan::Compile(None);
107
118
  }
108
119
  let key = Key {
109
120
  filename: filename.clone(),
@@ -121,9 +132,10 @@ impl CodeCache {
121
132
  }
122
133
  drop(entries);
123
134
  if lock(&self.refused).contains(&key) {
124
- return Plan::Compile;
135
+ return Plan::Compile(Some(key));
125
136
  }
126
- self.begin(key).map_or(Plan::Compile, Plan::Make)
137
+ self.begin(key.clone())
138
+ .map_or(Plan::Compile(Some(key)), Plan::Make)
127
139
  }
128
140
 
129
141
  /// Claims `key` for this context to build, unless another is building it.
@@ -300,7 +312,7 @@ mod tests {
300
312
  let cache = cache();
301
313
  assert!(matches!(
302
314
  cache.plan(&name(), &source(1), None),
303
- Plan::Compile
315
+ Plan::Compile(None)
304
316
  ));
305
317
  cached(cache, &source(1), Box::from(&b"compiled"[..]));
306
318
  assert!(matches!(
@@ -309,11 +321,11 @@ mod tests {
309
321
  ));
310
322
  assert!(matches!(
311
323
  cache.plan(&name(), &source(1), Some(7)),
312
- Plan::Compile
324
+ Plan::Compile(None)
313
325
  ));
314
326
  assert!(matches!(
315
327
  cache.plan(&JsText::from("other.js"), &source(1), None),
316
- Plan::Compile
328
+ Plan::Compile(None)
317
329
  ));
318
330
  }
319
331
 
@@ -355,10 +367,9 @@ mod tests {
355
367
  let _ = cache.plan(&name(), &source(3), None);
356
368
  let first = cache.plan(&name(), &source(3), None);
357
369
  assert!(matches!(first, Plan::Make(..)));
358
- assert!(matches!(
359
- cache.plan(&name(), &source(3), None),
360
- Plan::Compile
361
- ));
370
+ let elsewhere = cache.plan(&name(), &source(3), None);
371
+ assert!(matches!(elsewhere, Plan::Compile(Some(_))));
372
+ assert!(elsewhere.key() == first.key());
362
373
  drop(first);
363
374
  assert!(matches!(
364
375
  cache.plan(&name(), &source(3), None),
@@ -402,7 +413,7 @@ mod tests {
402
413
  assert_eq!(cache.stored(), 1);
403
414
  assert!(matches!(
404
415
  cache.plan(&name(), &source(7), None),
405
- Plan::Compile
416
+ Plan::Compile(Some(_))
406
417
  ));
407
418
  assert!(matches!(
408
419
  cache.plan(&name(), &source(6), None),
@@ -7,6 +7,7 @@ use mini_racer_sync::{ForkGate, Phase, lock};
7
7
 
8
8
  use crate::control::ControlBlock;
9
9
  use crate::process::code_cache::CodeCache;
10
+ use crate::process::sources::Sources;
10
11
  use crate::process::tasks::TaskRegistry;
11
12
  use crate::process::watchdog::Watchdog;
12
13
  use crate::process::workers::Workers;
@@ -51,13 +52,14 @@ pub struct Generation {
51
52
  watchdog: Mutex<Option<Arc<Watchdog>>>,
52
53
  workers: Workers,
53
54
  code_cache: CodeCache,
55
+ sources: Sources,
54
56
  next: OnceLock<Box<Self>>,
55
57
  }
56
58
 
57
59
  static ROOT: OnceLock<Generation> = OnceLock::new();
58
60
 
59
61
  impl Generation {
60
- fn new(epoch: u64, quiesced: bool, code_cache: CodeCache) -> Self {
62
+ fn new(epoch: u64, quiesced: bool, code_cache: CodeCache, sources: Sources) -> Self {
61
63
  Self {
62
64
  epoch,
63
65
  quiesced,
@@ -69,6 +71,7 @@ impl Generation {
69
71
  watchdog: Mutex::new(None),
70
72
  workers: Workers::default(),
71
73
  code_cache,
74
+ sources,
72
75
  next: OnceLock::new(),
73
76
  }
74
77
  }
@@ -94,6 +97,11 @@ impl Generation {
94
97
  &self.code_cache
95
98
  }
96
99
 
100
+ #[must_use]
101
+ pub const fn sources(&self) -> &Sources {
102
+ &self.sources
103
+ }
104
+
97
105
  pub fn register(&self, block: &Arc<ControlBlock>) {
98
106
  let mut blocks = lock(&self.blocks);
99
107
  blocks.retain(|block| block.strong_count() > 0);
@@ -115,7 +123,8 @@ impl Generation {
115
123
 
116
124
  pub fn current() -> &'static Generation {
117
125
  let epoch = epoch();
118
- let mut generation = ROOT.get_or_init(|| Generation::new(epoch, true, CodeCache::default()));
126
+ let mut generation =
127
+ ROOT.get_or_init(|| Generation::new(epoch, true, CodeCache::default(), Sources::default()));
119
128
  while generation.epoch != epoch {
120
129
  let quiesced = generation.quiesced && generation.prepared.load(Ordering::SeqCst);
121
130
  let next = generation.epoch.saturating_add(1);
@@ -125,6 +134,7 @@ pub fn current() -> &'static Generation {
125
134
  next,
126
135
  quiesced,
127
136
  parent.code_cache.inherited(),
137
+ parent.sources.inherited(),
128
138
  ))
129
139
  });
130
140
  }