summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
authorBartek Iwańczuk <biwanczuk@gmail.com>2023-02-21 21:12:22 +0100
committerGitHub <noreply@github.com>2023-02-21 21:12:22 +0100
commit69c0b05f7ab72f957ce7685998d3f424fb7e812c (patch)
tree7c4cf2b80cc3af8f968cbce460e05d255e749eb4 /core/runtime.rs
parent3479bc76613761cf31f7557d482e691274c365f1 (diff)
refactor(core): More efficient serde for ES modules in snapshot (#17856)
Instead of relying on "serde_v8" which is very inefficient in serializing enums, I'm hand rolling serde for "ModuleMap" data that is stored in the V8 snapshot to make ES modules snapshottable. ``` // this branch Benchmark #2: ./target/release/deno run empty.js Time (mean ± σ): 21.4 ms ± 0.9 ms [User: 15.6 ms, System: 6.4 ms] Range (min … max): 20.2 ms … 24.4 ms // main branch Benchmark #2: ./target/release/deno run empty.js Time (mean ± σ): 23.1 ms ± 1.2 ms [User: 17.0 ms, System: 6.2 ms] Range (min … max): 21.0 ms … 26.0 ms ```
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/core/runtime.rs b/core/runtime.rs
index d098c25b1..9c6b7afea 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -438,7 +438,7 @@ impl JsRuntime {
fn get_context_data(
scope: &mut v8::HandleScope<()>,
context: v8::Local<v8::Context>,
- ) -> (Vec<v8::Global<v8::Module>>, v8::Global<v8::Object>) {
+ ) -> (Vec<v8::Global<v8::Module>>, v8::Global<v8::Array>) {
fn data_error_to_panic(err: v8::DataError) -> ! {
match err {
v8::DataError::BadType { actual, expected } => {
@@ -457,15 +457,11 @@ impl JsRuntime {
// The 0th element is the module map itself, followed by X number of module
// handles. We need to deserialize the "next_module_id" field from the
// map to see how many module handles we expect.
- match scope.get_context_data_from_snapshot_once::<v8::Object>(0) {
+ match scope.get_context_data_from_snapshot_once::<v8::Array>(0) {
Ok(val) => {
let next_module_id = {
- let info_str = v8::String::new(&mut scope, "info").unwrap();
- let info_data: v8::Local<v8::Array> = val
- .get(&mut scope, info_str.into())
- .unwrap()
- .try_into()
- .unwrap();
+ let info_data: v8::Local<v8::Array> =
+ val.get_index(&mut scope, 1).unwrap().try_into().unwrap();
info_data.length()
};
@@ -3648,7 +3644,7 @@ pub mod tests {
main,
name: specifier.to_string(),
requests: vec![crate::modules::ModuleRequest {
- specifier: crate::resolve_url(&format!("file:///{prev}.js")).unwrap(),
+ specifier: format!("file:///{prev}.js"),
asserted_module_type: AssertedModuleType::JavaScriptOrWasm,
}],
module_type: ModuleType::JavaScript,