22
33mod bench_complex_replace_source;
44mod bench_source_map;
5+ mod benchmark_repetitive_react_components;
56
67use std:: collections:: HashMap ;
78
@@ -22,6 +23,11 @@ use bench_source_map::{
2223 benchmark_stringify_source_map_to_json,
2324} ;
2425
26+ use benchmark_repetitive_react_components:: {
27+ benchmark_repetitive_react_components_map,
28+ benchmark_repetitive_react_components_source,
29+ } ;
30+
2531const HELLOWORLD_JS : & str = include_str ! ( concat!(
2632 env!( "CARGO_MANIFEST_DIR" ) ,
2733 "/benches/fixtures/transpile-minify/files/helloworld.js"
@@ -106,66 +112,7 @@ fn benchmark_concat_generate_string_with_cache(b: &mut Bencher) {
106112 } )
107113}
108114
109- fn benchmark_concat_generate_base64 ( b : & mut Bencher ) {
110- let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
111- value : HELLOWORLD_MIN_JS ,
112- name : "helloworld.min.js" ,
113- source_map : SourceMap :: from_json ( HELLOWORLD_MIN_JS_MAP ) . unwrap ( ) ,
114- original_source : Some ( HELLOWORLD_JS . to_string ( ) ) ,
115- inner_source_map : Some ( SourceMap :: from_json ( HELLOWORLD_JS_MAP ) . unwrap ( ) ) ,
116- remove_original_source : false ,
117- } ) ;
118- let sms_rollup = SourceMapSource :: new ( SourceMapSourceOptions {
119- value : BUNDLE_JS ,
120- name : "bundle.js" ,
121- source_map : SourceMap :: from_json ( BUNDLE_JS_MAP ) . unwrap ( ) ,
122- original_source : None ,
123- inner_source_map : None ,
124- remove_original_source : false ,
125- } ) ;
126- let concat = ConcatSource :: new ( [ sms_minify, sms_rollup] ) ;
127-
128- b. iter ( || {
129- let json = concat
130- . map ( & MapOptions :: default ( ) )
131- . unwrap ( )
132- . to_json ( )
133- . unwrap ( ) ;
134- let _ = base64_simd:: STANDARD . encode_to_string ( json. as_bytes ( ) ) ;
135- } )
136- }
137-
138- fn benchmark_concat_generate_base64_with_cache ( b : & mut Bencher ) {
139- let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
140- value : HELLOWORLD_MIN_JS ,
141- name : "helloworld.min.js" ,
142- source_map : SourceMap :: from_json ( HELLOWORLD_MIN_JS_MAP ) . unwrap ( ) ,
143- original_source : Some ( HELLOWORLD_JS . to_string ( ) ) ,
144- inner_source_map : Some ( SourceMap :: from_json ( HELLOWORLD_JS_MAP ) . unwrap ( ) ) ,
145- remove_original_source : false ,
146- } ) ;
147- let sms_rollup = SourceMapSource :: new ( SourceMapSourceOptions {
148- value : BUNDLE_JS ,
149- name : "bundle.js" ,
150- source_map : SourceMap :: from_json ( BUNDLE_JS_MAP ) . unwrap ( ) ,
151- original_source : None ,
152- inner_source_map : None ,
153- remove_original_source : false ,
154- } ) ;
155- let concat = ConcatSource :: new ( [ sms_minify, sms_rollup] ) ;
156- let cached = CachedSource :: new ( concat) ;
157-
158- b. iter ( || {
159- let json = cached
160- . map ( & MapOptions :: default ( ) )
161- . unwrap ( )
162- . to_json ( )
163- . unwrap ( ) ;
164- let _ = base64_simd:: STANDARD . encode_to_string ( json. as_bytes ( ) ) ;
165- } )
166- }
167-
168- fn benchmark_concat_generate_string_with_cache_as_key ( b : & mut Bencher ) {
115+ fn benchmark_cached_source_hash ( b : & mut Bencher ) {
169116 let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
170117 value : HELLOWORLD_MIN_JS ,
171118 name : "helloworld.min.js" ,
@@ -193,41 +140,8 @@ fn benchmark_concat_generate_string_with_cache_as_key(b: &mut Bencher) {
193140 } )
194141}
195142
196- fn benchmark_concat_generate_string_as_key ( b : & mut Bencher ) {
197- let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
198- value : HELLOWORLD_MIN_JS ,
199- name : "helloworld.min.js" ,
200- source_map : SourceMap :: from_json ( HELLOWORLD_MIN_JS_MAP ) . unwrap ( ) ,
201- original_source : Some ( HELLOWORLD_JS . to_string ( ) ) ,
202- inner_source_map : Some ( SourceMap :: from_json ( HELLOWORLD_JS_MAP ) . unwrap ( ) ) ,
203- remove_original_source : false ,
204- } ) ;
205- let sms_rollup = SourceMapSource :: new ( SourceMapSourceOptions {
206- value : BUNDLE_JS ,
207- name : "bundle.js" ,
208- source_map : SourceMap :: from_json ( BUNDLE_JS_MAP ) . unwrap ( ) ,
209- original_source : None ,
210- inner_source_map : None ,
211- remove_original_source : false ,
212- } ) ;
213- let concat = ConcatSource :: new ( [ sms_minify, sms_rollup] ) . boxed ( ) ;
214-
215- b. iter ( || {
216- let mut m = HashMap :: < BoxSource , ( ) > :: new ( ) ;
217- m. insert ( concat. clone ( ) , ( ) ) ;
218- let _ = black_box ( || m. get ( & concat) ) ;
219- let _ = black_box ( || m. get ( & concat) ) ;
220- } )
221- }
222-
223143fn bench_rspack_sources ( criterion : & mut Criterion ) {
224144 let mut group = criterion. benchmark_group ( "rspack_sources" ) ;
225- group. bench_function (
226- "concat_generate_base64_with_cache" ,
227- benchmark_concat_generate_base64_with_cache,
228- ) ;
229- group
230- . bench_function ( "concat_generate_base64" , benchmark_concat_generate_base64) ;
231145
232146 group. bench_function (
233147 "concat_generate_string_with_cache" ,
@@ -236,14 +150,7 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
236150 group
237151 . bench_function ( "concat_generate_string" , benchmark_concat_generate_string) ;
238152
239- group. bench_function (
240- "concat_generate_string_with_cache_as_key" ,
241- benchmark_concat_generate_string_with_cache_as_key,
242- ) ;
243- group. bench_function (
244- "concat_generate_string_as_key" ,
245- benchmark_concat_generate_string_as_key,
246- ) ;
153+ group. bench_function ( "cached_source_hash" , benchmark_cached_source_hash) ;
247154
248155 group
249156 . bench_function ( "complex_replace_source" , benchmark_complex_replace_source) ;
@@ -260,6 +167,16 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
260167 benchmark_stringify_source_map_to_json,
261168 ) ;
262169
170+ group. bench_function (
171+ "repetitive_react_components_map" ,
172+ benchmark_repetitive_react_components_map,
173+ ) ;
174+
175+ group. bench_function (
176+ "repetitive_react_components_source" ,
177+ benchmark_repetitive_react_components_source,
178+ ) ;
179+
263180 group. finish ( ) ;
264181}
265182
0 commit comments