Skip to content

Commit fe371d6

Browse files
committed
updates
1 parent a28aa5e commit fe371d6

File tree

4 files changed

+36
-83
lines changed

4 files changed

+36
-83
lines changed

Cargo.lock

+2-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,6 @@ opt-level = 3
368368
opt-level = 3
369369
[profile.release.package.base64-simd]
370370
opt-level = 3
371+
372+
[patch.crates-io]
373+
deno_core = { path = "../deno_core/core" }

cli/cache/module_info.rs

-17
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,6 @@ impl ModuleInfoCache {
102102
}
103103
}
104104

105-
pub fn get_module_source_hash(
106-
&self,
107-
specifier: &ModuleSpecifier,
108-
media_type: MediaType,
109-
) -> Result<Option<ModuleInfoCacheSourceHash>, AnyError> {
110-
let query = "SELECT source_hash FROM moduleinfocache WHERE specifier=?1 AND media_type=?2";
111-
let res = self.conn.query_row(
112-
query,
113-
params![specifier.as_str(), serialize_media_type(media_type)],
114-
|row| {
115-
let source_hash: String = row.get(0)?;
116-
Ok(ModuleInfoCacheSourceHash(source_hash))
117-
},
118-
)?;
119-
Ok(res)
120-
}
121-
122105
pub fn get_module_info(
123106
&self,
124107
specifier: &ModuleSpecifier,

cli/module_loader.rs

+31-58
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::args::CliOptions;
1313
use crate::args::DenoSubcommand;
1414
use crate::args::TsTypeLib;
1515
use crate::cache::CodeCache;
16+
use crate::cache::FastInsecureHasher;
1617
use crate::cache::ModuleInfoCache;
1718
use crate::cache::ParsedSourceCache;
1819
use crate::emit::Emitter;
@@ -51,6 +52,7 @@ use deno_core::ModuleCodeString;
5152
use deno_core::ModuleLoader;
5253
use deno_core::ModuleSource;
5354
use deno_core::ModuleSourceCode;
55+
use deno_core::ModuleSourceCodeCache;
5456
use deno_core::ModuleSpecifier;
5557
use deno_core::ModuleType;
5658
use deno_core::RequestedModuleType;
@@ -388,27 +390,24 @@ impl<TGraphContainer: ModuleGraphContainer>
388390
}
389391

390392
let code_cache = if module_type == ModuleType::JavaScript {
391-
self.shared.code_cache.as_ref().and_then(|cache| {
392-
let code_hash = self
393-
.get_code_hash_or_timestamp(specifier, code_source.media_type)
394-
.ok()
395-
.flatten();
396-
if let Some(code_hash) = code_hash {
397-
cache
398-
.get_sync(
399-
specifier.as_str(),
400-
code_cache::CodeCacheType::EsModule,
401-
&code_hash,
402-
)
403-
.map(Cow::from)
404-
.inspect(|_| {
405-
// This log line is also used by tests.
406-
log::debug!(
407-
"V8 code cache hit for ES module: {specifier}, [{code_hash:?}]"
408-
);
409-
})
410-
} else {
411-
None
393+
self.shared.code_cache.as_ref().map(|cache| {
394+
let code_hash = FastInsecureHasher::hash(&code);
395+
let data = cache
396+
.get_sync(
397+
specifier.as_str(),
398+
code_cache::CodeCacheType::EsModule,
399+
&code_hash.to_string(),
400+
)
401+
.map(Cow::from)
402+
.inspect(|_| {
403+
// This log line is also used by tests.
404+
log::debug!(
405+
"V8 code cache hit for ES module: {specifier}, [{code_hash:?}]"
406+
);
407+
});
408+
ModuleSourceCodeCache {
409+
hash: code_hash,
410+
data,
412411
}
413412
})
414413
} else {
@@ -589,25 +588,6 @@ impl<TGraphContainer: ModuleGraphContainer>
589588
resolution.map_err(|err| err.into())
590589
}
591590

592-
fn get_code_hash_or_timestamp(
593-
&self,
594-
specifier: &ModuleSpecifier,
595-
media_type: MediaType,
596-
) -> Result<Option<String>, AnyError> {
597-
let hash = self
598-
.shared
599-
.module_info_cache
600-
.get_module_source_hash(specifier, media_type)?;
601-
if let Some(hash) = hash {
602-
return Ok(Some(hash.into()));
603-
}
604-
605-
// Use the modified timestamp from the local file system if we don't have a hash.
606-
let timestamp = code_timestamp(specifier.as_str())
607-
.map(|timestamp| timestamp.to_string())?;
608-
Ok(Some(timestamp))
609-
}
610-
611591
async fn load_prepared_module(
612592
&self,
613593
specifier: &ModuleSpecifier,
@@ -866,27 +846,20 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
866846
fn code_cache_ready(
867847
&self,
868848
specifier: &ModuleSpecifier,
849+
hash: u64,
869850
code_cache: &[u8],
870851
) -> Pin<Box<dyn Future<Output = ()>>> {
871852
if let Some(cache) = self.0.shared.code_cache.as_ref() {
872-
let media_type = MediaType::from_specifier(specifier);
873-
let code_hash = self
874-
.0
875-
.get_code_hash_or_timestamp(specifier, media_type)
876-
.ok()
877-
.flatten();
878-
if let Some(code_hash) = code_hash {
879-
// This log line is also used by tests.
880-
log::debug!(
881-
"Updating V8 code cache for ES module: {specifier}, [{code_hash:?}]"
882-
);
883-
cache.set_sync(
884-
specifier.as_str(),
885-
code_cache::CodeCacheType::EsModule,
886-
&code_hash,
887-
code_cache,
888-
);
889-
}
853+
// This log line is also used by tests.
854+
log::debug!(
855+
"Updating V8 code cache for ES module: {specifier}, [{hash}]"
856+
);
857+
cache.set_sync(
858+
specifier.as_str(),
859+
code_cache::CodeCacheType::EsModule,
860+
&hash.to_string(),
861+
code_cache,
862+
);
890863
}
891864
std::future::ready(()).boxed_local()
892865
}

0 commit comments

Comments
 (0)