From b3d7df55357ea6fc6f5141b64a9638ddb39b0f63 Mon Sep 17 00:00:00 2001 From: Igor Zinkovsky Date: Wed, 17 Apr 2024 07:19:55 -0700 Subject: perf: v8 code cache (#23081) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR enables V8 code cache for ES modules and for `require` scripts through `op_eval_context`. Code cache artifacts are transparently stored and fetched using sqlite db and are passed to V8. `--no-code-cache` can be used to disable. --------- Co-authored-by: Bartek IwaƄczuk --- runtime/code_cache.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 runtime/code_cache.rs (limited to 'runtime/code_cache.rs') diff --git a/runtime/code_cache.rs b/runtime/code_cache.rs new file mode 100644 index 000000000..ccc070365 --- /dev/null +++ b/runtime/code_cache.rs @@ -0,0 +1,31 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +pub enum CodeCacheType { + EsModule, + Script, +} + +impl CodeCacheType { + pub fn as_str(&self) -> &str { + match self { + Self::EsModule => "esmodule", + Self::Script => "script", + } + } +} + +pub trait CodeCache: Send + Sync { + fn get_sync( + &self, + specifier: &str, + code_cache_type: CodeCacheType, + source_hash: &str, + ) -> Option>; + fn set_sync( + &self, + specifier: &str, + code_cache_type: CodeCacheType, + source_hash: &str, + data: &[u8], + ); +} -- cgit v1.2.3