Skip to content

Commit

Permalink
feat(persistent cache): add make occasion (#8586)
Browse files Browse the repository at this point in the history
feat: make occasion
  • Loading branch information
jerrykingxyz authored Dec 6, 2024
1 parent 9e1205c commit ec760c2
Show file tree
Hide file tree
Showing 206 changed files with 1,778 additions and 142 deletions.
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ rustflags = [
"-Wclippy::empty_structs_with_brackets",
"-Wclippy::rc_buffer",
"-Wclippy::rc_mutex",
"-Wclippy::same_name_method",
# https://github.com/bitflags/bitflags/issues/424
# "-Wclippy::same_name_method",

"-Aclippy::default_constructed_unit_structs",
"--cfg", "tokio_unstable"
Expand Down
29 changes: 28 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ rustc-hash = { version = "2.1.0" }
serde = { version = "1.0.215" }
serde_json = { version = "1.0.133" }
simd-json = { version = "0.14.0-rc.2" }
smol_str = { version = "0.3.0" }
stacker = { version = "0.1.17" }
sugar_path = { version = "1.2.0", features = ["cached_current_dir"] }
syn = { version = "2.0.90" }
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_binding_options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ napi = { workspace = true, features = ["async"
napi-derive = { workspace = true }
pollster = { workspace = true }
rspack_binding_values = { workspace = true }
rspack_cacheable = { workspace = true }
rspack_collections = { workspace = true }
rspack_core = { workspace = true }
rspack_error = { workspace = true }
Expand Down
20 changes: 12 additions & 8 deletions crates/rspack_binding_options/src/plugins/js_loader/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
sync::{Arc, LazyLock},
};

use rspack_cacheable::{cacheable, cacheable_dyn};
use rspack_collections::{Identifiable, Identifier};
use rspack_core::{
BoxLoader, Context, Loader, ModuleRuleUseLoader, NormalModuleFactoryResolveLoader, ResolveResult,
Expand All @@ -24,9 +25,11 @@ use tokio::sync::RwLock;

use super::{JsLoaderRspackPlugin, JsLoaderRspackPluginInner};

#[cacheable]
#[derive(Debug)]
pub struct JsLoader(pub Identifier);

#[cacheable_dyn]
impl Loader<RunnerContext> for JsLoader {}

impl Identifiable for JsLoader {
Expand Down Expand Up @@ -60,14 +63,15 @@ pub async fn get_builtin_loader(builtin: &str, options: Option<&str>) -> Result<
}

let loader = Arc::new(
rspack_loader_swc::SwcLoader::new(serde_json::from_str(options.as_ref()).map_err(|e| {
serde_error_to_miette(
e,
options.clone(),
"failed to parse builtin:swc-loader options",
)
})?)
.with_identifier(builtin.into()),
rspack_loader_swc::SwcLoader::new(options.as_ref())
.map_err(|e| {
serde_error_to_miette(
e,
options.clone(),
"failed to parse builtin:swc-loader options",
)
})?
.with_identifier(builtin.into()),
);

SWC_LOADER_CACHE.write().await.insert(
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_cacheable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ rspack_macros = { workspace = true }
rspack_resolver = { workspace = true }
rspack_sources = { workspace = true }
serde_json = { workspace = true }
smol_str = { workspace = true }
swc_core = { workspace = true, features = ["ecma_ast"] }
ustr = { workspace = true }
1 change: 1 addition & 0 deletions crates/rspack_cacheable/src/with/as_preset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod lightningcss;
mod rspack_resolver;
mod rspack_sources;
mod serde_json;
mod smol_str;
mod swc;
mod ustr;

Expand Down
41 changes: 41 additions & 0 deletions crates/rspack_cacheable/src/with/as_preset/smol_str.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use rkyv::{
rancor::{Fallible, Source},
ser::Writer,
string::{ArchivedString, StringResolver},
with::{ArchiveWith, DeserializeWith, SerializeWith},
Place,
};
use smol_str::SmolStr;

use super::AsPreset;

impl ArchiveWith<SmolStr> for AsPreset {
type Archived = ArchivedString;
type Resolver = StringResolver;

#[inline]
fn resolve_with(field: &SmolStr, resolver: Self::Resolver, out: Place<Self::Archived>) {
ArchivedString::resolve_from_str(field.as_str(), resolver, out);
}
}

impl<S> SerializeWith<SmolStr, S> for AsPreset
where
S: ?Sized + Fallible + Writer,
S::Error: Source,
{
#[inline]
fn serialize_with(field: &SmolStr, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
ArchivedString::serialize_from_str(field.as_str(), serializer)
}
}

impl<D> DeserializeWith<ArchivedString, SmolStr, D> for AsPreset
where
D: ?Sized + Fallible,
{
#[inline]
fn deserialize_with(field: &ArchivedString, _: &mut D) -> Result<SmolStr, D::Error> {
Ok(SmolStr::from(field.as_str()))
}
}
13 changes: 13 additions & 0 deletions crates/rspack_cacheable/src/with/as_ref_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,16 @@ impl AsRefStrConverter for Arc<str> {
}
}
}

// for Box<str>
impl AsRefStrConverter for Box<str> {
fn as_str(&self) -> &str {
self
}
fn from_str(s: &str) -> Self
where
Self: Sized,
{
s.into()
}
}
13 changes: 0 additions & 13 deletions crates/rspack_cacheable/src/with/as_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,3 @@ impl AsStringConverter for PathBuf {
Ok(PathBuf::from(s))
}
}

// for Box<str>
impl AsStringConverter for Box<str> {
fn to_string(&self) -> Result<String, SerializeError> {
Ok(str::to_string(self))
}
fn from_str(s: &str) -> Result<Self, DeserializeError>
where
Self: Sized,
{
Ok(s.into())
}
}
Loading

2 comments on commit ec760c2

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-12-06 37e17cf) Current Change
10000_big_production-mode_disable-minimize + exec 37 s ± 441 ms 36.9 s ± 325 ms -0.14 %
10000_development-mode + exec 1.78 s ± 32 ms 1.79 s ± 25 ms +0.80 %
10000_development-mode_hmr + exec 637 ms ± 6.1 ms 649 ms ± 8.1 ms +1.91 %
10000_production-mode + exec 2.33 s ± 34 ms 2.36 s ± 60 ms +1.22 %
arco-pro_development-mode + exec 1.71 s ± 60 ms 1.77 s ± 66 ms +3.06 %
arco-pro_development-mode_hmr + exec 424 ms ± 1.5 ms 425 ms ± 3.6 ms +0.24 %
arco-pro_production-mode + exec 3.11 s ± 93 ms 3.19 s ± 53 ms +2.30 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.17 s ± 49 ms 3.18 s ± 81 ms +0.46 %
threejs_development-mode_10x + exec 1.62 s ± 12 ms 1.62 s ± 14 ms +0.53 %
threejs_development-mode_10x_hmr + exec 785 ms ± 10 ms 786 ms ± 11 ms +0.09 %
threejs_production-mode_10x + exec 4.87 s ± 36 ms 4.88 s ± 31 ms +0.13 %
10000_big_production-mode_disable-minimize + rss memory 10019 MiB ± 41.2 MiB 9971 MiB ± 129 MiB -0.48 %
10000_development-mode + rss memory 811 MiB ± 21.7 MiB 825 MiB ± 29.3 MiB +1.72 %
10000_development-mode_hmr + rss memory 1944 MiB ± 427 MiB 1956 MiB ± 185 MiB +0.61 %
10000_production-mode + rss memory 701 MiB ± 23.4 MiB 694 MiB ± 32.6 MiB -1.08 %
arco-pro_development-mode + rss memory 709 MiB ± 28.4 MiB 711 MiB ± 38.4 MiB +0.28 %
arco-pro_development-mode_hmr + rss memory 896 MiB ± 57.1 MiB 930 MiB ± 63.9 MiB +3.73 %
arco-pro_production-mode + rss memory 822 MiB ± 35 MiB 807 MiB ± 50.4 MiB -1.86 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 828 MiB ± 54 MiB 848 MiB ± 34.7 MiB +2.39 %
threejs_development-mode_10x + rss memory 789 MiB ± 51 MiB 778 MiB ± 59.3 MiB -1.40 %
threejs_development-mode_10x_hmr + rss memory 1748 MiB ± 170 MiB 1576 MiB ± 226 MiB -9.83 %
threejs_production-mode_10x + rss memory 1117 MiB ± 78.8 MiB 1144 MiB ± 58.5 MiB +2.44 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
rsdoctor ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ✅ success
devserver ✅ success
nuxt ✅ success

Please sign in to comment.