diff options
author | Igor Zinkovsky <igor@deno.com> | 2024-04-17 07:19:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 07:19:55 -0700 |
commit | b3d7df55357ea6fc6f5141b64a9638ddb39b0f63 (patch) | |
tree | 0ca14140c7e080ed3367a7352bbaf3ed5f7a0f48 /cli/cache/module_info.rs | |
parent | 9acbf90b06bf79dd6e4cf2428b3566da009bed65 (diff) |
perf: v8 code cache (#23081)
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 <biwanczuk@gmail.com>
Diffstat (limited to 'cli/cache/module_info.rs')
-rw-r--r-- | cli/cache/module_info.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cli/cache/module_info.rs b/cli/cache/module_info.rs index 6d317b216..2e9274160 100644 --- a/cli/cache/module_info.rs +++ b/cli/cache/module_info.rs @@ -39,6 +39,7 @@ pub static MODULE_INFO_CACHE_DB: CacheDBConfiguration = CacheDBConfiguration { on_failure: CacheFailure::InMemory, }; +#[derive(Debug)] pub struct ModuleInfoCacheSourceHash(String); impl ModuleInfoCacheSourceHash { @@ -55,6 +56,12 @@ impl ModuleInfoCacheSourceHash { } } +impl From<ModuleInfoCacheSourceHash> for String { + fn from(source_hash: ModuleInfoCacheSourceHash) -> String { + source_hash.0 + } +} + /// A cache of `deno_graph::ModuleInfo` objects. Using this leads to a considerable /// performance improvement because when it exists we can skip parsing a module for /// deno_graph. @@ -80,6 +87,23 @@ impl ModuleInfoCache { } } + pub fn get_module_source_hash( + &self, + specifier: &ModuleSpecifier, + media_type: MediaType, + ) -> Result<Option<ModuleInfoCacheSourceHash>, AnyError> { + let query = "SELECT source_hash FROM moduleinfocache WHERE specifier=?1 AND media_type=?2"; + let res = self.conn.query_row( + query, + params![specifier.as_str(), serialize_media_type(media_type)], + |row| { + let source_hash: String = row.get(0)?; + Ok(ModuleInfoCacheSourceHash(source_hash)) + }, + )?; + Ok(res) + } + pub fn get_module_info( &self, specifier: &ModuleSpecifier, |