mirror of
https://github.com/swc-project/swc.git
synced 2024-12-26 07:02:28 +03:00
fix(plugin/runner): Use fs cache properly (#7748)
This commit is contained in:
parent
875a7a7393
commit
1122de7d8b
@ -696,17 +696,17 @@ impl Options {
|
||||
// target.
|
||||
init_plugin_module_cache_once(true, &experimental.cache_root);
|
||||
|
||||
let mut inner_cache = PLUGIN_MODULE_CACHE
|
||||
.inner
|
||||
.get()
|
||||
.expect("Cache should be available")
|
||||
.lock();
|
||||
|
||||
// Populate cache to the plugin modules if not loaded
|
||||
for plugin_config in plugins.iter() {
|
||||
let plugin_name = &plugin_config.0;
|
||||
|
||||
if !PLUGIN_MODULE_CACHE
|
||||
.inner
|
||||
.get()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.contains(&plugin_name)
|
||||
{
|
||||
if !inner_cache.contains(&plugin_name) {
|
||||
let resolved_path = plugin_resolver.resolve(
|
||||
&FileName::Real(PathBuf::from(&plugin_name)),
|
||||
&plugin_name,
|
||||
@ -718,12 +718,8 @@ impl Options {
|
||||
anyhow::bail!("Failed to resolve plugin path: {:?}", resolved_path);
|
||||
};
|
||||
|
||||
let mut inner_cache = PLUGIN_MODULE_CACHE
|
||||
.inner
|
||||
.get()
|
||||
.expect("Cache should be available")
|
||||
.lock();
|
||||
inner_cache.store_bytes_from_path(&path, &plugin_name)?;
|
||||
tracing::debug!("Initialized WASM plugin {plugin_name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,9 +116,17 @@ impl PluginModuleCacheInner {
|
||||
if let Some(fs_cache_store) = &mut self.fs_cache_store {
|
||||
let module_bytes_hash = Hash::generate(&raw_module_bytes);
|
||||
let store = new_store();
|
||||
let module = Module::new(&store, raw_module_bytes.clone())
|
||||
.context("Cannot compile plugin binary")?;
|
||||
fs_cache_store.store(module_bytes_hash, &module)?;
|
||||
|
||||
let module =
|
||||
if let Ok(module) = unsafe { fs_cache_store.load(&store, module_bytes_hash) } {
|
||||
tracing::debug!("Build WASM from cache: {key}");
|
||||
module
|
||||
} else {
|
||||
let module = Module::new(&store, raw_module_bytes.clone())
|
||||
.context("Cannot compile plugin binary")?;
|
||||
fs_cache_store.store(module_bytes_hash, &module)?;
|
||||
module
|
||||
};
|
||||
|
||||
// Store hash to load from fs_cache_store later.
|
||||
self.fs_cache_hash_store
|
||||
|
Loading…
Reference in New Issue
Block a user