Skip to content

Commit

Permalink
perf: use MapCachedSource
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Dec 5, 2024
1 parent 0d1d075 commit a211427
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ rayon = { version = "1.10.0" }
regex = { version = "1.11.1" }
ropey = "1.6.1"
rspack_resolver = { version = "0.3.5", features = ["package_json_raw_json_api"] }
rspack_sources = { version = "=0.3.6" }
rspack_sources = { git = "https://github.com/web-infra-dev/rspack-sources", rev = "30b24267f406a03ce8d958a9acf2f8db9d50913c" }
rustc-hash = { version = "2.1.0" }
serde = { version = "1.0.215" }
serde_json = { version = "1.0.133" }
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_binding_values/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl ToJsCompatSourceOwned for dyn Source + '_ {
}

fn to_webpack_map(source: &dyn Source) -> Result<Option<String>> {
let map = source.map(&MapOptions::default());
let map = source.map(&MapOptions::default(), &Default::default());

map
.map(|m| m.to_json())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
field: &BoxSource,
serializer: &mut S,
) -> Result<Self::Resolver, SerializeError> {
let map = match field.map(&Default::default()) {
let map = match field.map(&Default::default(), &Default::default()) {
Some(map) => Some(
map
.to_json()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fn test_rspack_source() {
let new_data: Data = from_bytes(&bytes, &()).unwrap();
assert_eq!(data.0.buffer(), new_data.0.buffer());
assert_eq!(
data.0.map(&Default::default()),
new_data.0.map(&Default::default())
data.0.map(&Default::default(), &Default::default()),
new_data.0.map(&Default::default(), &Default::default())
);
}

Expand Down
6 changes: 4 additions & 2 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use rspack_collections::{
use rspack_error::{Diagnosable, Diagnostic, DiagnosticKind, Result, TraceableError};
use rspack_hash::{HashDigest, HashFunction, RspackHash};
use rspack_hook::define_hook;
use rspack_sources::{ConcatSource, RawSource, RawStringSource, ReplaceSource, Source, SourceExt};
use rspack_sources::{
ConcatSource, MapCachedSource, RawStringSource, ReplaceSource, Source, SourceExt,
};
use rspack_util::{ext::DynHash, itoa, source_map::SourceMapKind, swc::join_atom};
use rustc_hash::FxHasher;
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
Expand Down Expand Up @@ -1280,7 +1282,7 @@ impl Module for ConcatenatedModule {
}

let mut code_generation_result = CodeGenerationResult::default();
code_generation_result.add(SourceType::JavaScript, result.boxed());
code_generation_result.add(SourceType::JavaScript, MapCachedSource::new(result).boxed());
code_generation_result.chunk_init_fragments = chunk_init_fragments;
code_generation_result.runtime_requirements = runtime_requirements;
code_generation_result
Expand Down
7 changes: 5 additions & 2 deletions crates/rspack_core/src/normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rspack_hook::define_hook;
use rspack_loader_runner::{run_loaders, AdditionalData, Content, LoaderContext, ResourceData};
use rspack_macros::impl_source_map_config;
use rspack_sources::{
BoxSource, OriginalSource, RawBufferSource, RawSource, RawStringSource, Source, SourceExt,
BoxSource, MapCachedSource, OriginalSource, RawBufferSource, RawStringSource, Source, SourceExt,
SourceMap, SourceMapSource, WithoutOriginalOptions,
};
use rspack_util::{
Expand Down Expand Up @@ -650,7 +650,10 @@ impl Module for NormalModule {
concatenation_scope: concatenation_scope.as_mut(),
},
)?;
code_generation_result.add(*source_type, generation_result.boxed());
code_generation_result.add(
*source_type,
MapCachedSource::new(generation_result).boxed(),
);
}
code_generation_result.concatenation_scope = concatenation_scope;
Ok(code_generation_result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ fn eval_source_map_devtool_plugin_render_module_content(
if let Some(cached_source) = self.cache.get(&origin_source) {
render_source.source = cached_source.value().clone();
return Ok(());
} else if let Some(mut map) = origin_source.map(&MapOptions::new(self.columns)) {
} else if let Some(mut map) =
origin_source.map(&MapOptions::new(self.columns), &Default::default())
{
let source = {
let source = &origin_source.source();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl SourceMapDevToolPlugin {
};
let source = if is_match {
asset.get_source().map(|source| {
let source_map = source.map(&map_options);
let source_map = source.map(&map_options, &Default::default());
(file, source, source_map)
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_lightning_css_minimizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {

if let Some(original_source) = original.get_source() {
let input = original_source.source().into_owned();
let input_source_map = original_source.map(&MapOptions::default());
let input_source_map = original_source.map(&MapOptions::default(), &Default::default());

let mut parser_flags = ParserFlags::empty();
parser_flags.set(
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_swc_js_minimizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
let filename = filename.split('?').next().expect("Should have filename");
if let Some(original_source) = original.get_source() {
let input = original_source.source().to_string();
let input_source_map = original_source.map(&MapOptions::default());
let input_source_map = original_source.map(&MapOptions::default(), &Default::default());

let is_module = if let Some(module) = minimizer_options.module {
Some(module)
Expand Down

0 comments on commit a211427

Please sign in to comment.