1+ #![ allow( missing_docs) ]
2+
13#[ cfg( not( codspeed) ) ]
24pub use criterion:: * ;
35
46#[ cfg( codspeed) ]
57pub use codspeed_criterion_compat:: * ;
68
79use rspack_sources:: {
8- CachedSource , ConcatSource , MapOptions , Source , SourceMap , SourceMapSource ,
9- SourceMapSourceOptions ,
10+ CachedSource , ConcatSource , MapOptions , ReplaceSource , Source , SourceMap ,
11+ SourceMapSource , SourceMapSourceOptions ,
1012} ;
1113
1214const HELLOWORLD_JS : & str = include_str ! ( concat!(
@@ -33,6 +35,14 @@ const BUNDLE_JS_MAP: &str = include_str!(concat!(
3335 env!( "CARGO_MANIFEST_DIR" ) ,
3436 "/benches/fixtures/transpile-rollup/files/bundle.js.map"
3537) ) ;
38+ const ANTD_MIN_JS : & str = include_str ! ( concat!(
39+ env!( "CARGO_MANIFEST_DIR" ) ,
40+ "/benches/fixtures/antd-mini/antd.min.js"
41+ ) ) ;
42+ const ANTD_MIN_JS_MAP : & str = include_str ! ( concat!(
43+ env!( "CARGO_MANIFEST_DIR" ) ,
44+ "/benches/fixtures/antd-mini/antd.min.js.map"
45+ ) ) ;
3646
3747fn benchmark_concat_generate_string ( b : & mut Bencher ) {
3848 let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
@@ -152,6 +162,39 @@ fn benchmark_concat_generate_base64_with_cache(b: &mut Bencher) {
152162 } )
153163}
154164
165+ fn benchmark_replace_large_minified_source ( b : & mut Bencher ) {
166+ let antd_minify = SourceMapSource :: new ( SourceMapSourceOptions {
167+ value : ANTD_MIN_JS ,
168+ name : "antd.min.js" ,
169+ source_map : SourceMap :: from_json ( ANTD_MIN_JS_MAP ) . unwrap ( ) ,
170+ original_source : None ,
171+ inner_source_map : None ,
172+ remove_original_source : false ,
173+ } ) ;
174+ let mut replace_source = ReplaceSource :: new ( antd_minify) ;
175+ replace_source. replace ( 107 , 114 , "exports" , None ) ;
176+ replace_source. replace ( 130 , 143 , "'object'" , None ) ;
177+ replace_source. replace ( 165 , 172 , "__webpack_require__" , None ) ;
178+ replace_source. replace ( 173 , 180 , "/*! react */\" ./node_modules/.pnpm/react@18.2.0/node_modules/react/index.js\" " , None ) ;
179+ replace_source. replace ( 183 , 190 , "__webpack_require__" , None ) ;
180+ replace_source. replace ( 191 , 202 , "/*! react-dom */\" ./node_modules/.pnpm/react-dom@18.2.0_react@18.2.0/node_modules/react-dom/index.js\" " , None ) ;
181+ replace_source. replace ( 205 , 212 , "__webpack_require__" , None ) ;
182+ replace_source. replace ( 213 , 220 , "/*! dayjs */\" ./node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js\" " , None ) ;
183+ replace_source. replace ( 363 , 370 , "exports" , None ) ;
184+ replace_source. replace ( 373 , 385 , "exports.antd" , None ) ;
185+ replace_source. replace ( 390 , 397 , "__webpack_require__" , None ) ;
186+ replace_source. replace ( 398 , 405 , "/*! react */\" ./node_modules/.pnpm/react@18.2.0/node_modules/react/index.js\" " , None ) ;
187+ replace_source. replace ( 408 , 415 , "__webpack_require__" , None ) ;
188+ replace_source. replace ( 416 , 427 , "/*! react-dom */\" ./node_modules/.pnpm/react-dom@18.2.0_react@18.2.0/node_modules/react-dom/index.js\" " , None ) ;
189+ replace_source. replace ( 430 , 437 , "__webpack_require__" , None ) ;
190+ replace_source. replace ( 438 , 445 , "/*! dayjs */\" ./node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js\" " , None ) ;
191+ replace_source. replace ( 494 , 498 , "this" , None ) ;
192+
193+ b. iter ( || {
194+ replace_source. map ( & MapOptions :: default ( ) ) ;
195+ } ) ;
196+ }
197+
155198fn bench_rspack_sources ( criterion : & mut Criterion ) {
156199 let mut group = criterion. benchmark_group ( "rspack_sources" ) ;
157200 group. bench_function (
@@ -166,6 +209,10 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
166209 ) ;
167210 group
168211 . bench_function ( "concat_generate_string" , benchmark_concat_generate_string) ;
212+ group. bench_function (
213+ "replace_large_minified_source" ,
214+ benchmark_replace_large_minified_source,
215+ ) ;
169216 group. finish ( ) ;
170217}
171218
0 commit comments