Skip to content

Commit

Permalink
chore(plugin/runner): Fix benchmark (#9477)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Aug 21, 2024
1 parent 4bee30a commit b0b5e36
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
5 changes: 0 additions & 5 deletions crates/swc_plugin_runner/benches/assets/input.js

This file was deleted.

85 changes: 44 additions & 41 deletions crates/swc_plugin_runner/benches/ecma_invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use swc_common::{
use swc_ecma_ast::EsVersion;
use swc_ecma_parser::parse_file_as_program;

static SOURCE: &str = include_str!("./assets/input.js");
static SOURCE: &str = include_str!("../../swc_ecma_minifier/benches/full/typescript.js");

fn plugin_group(c: &mut Criterion) {
let plugin_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
Expand Down Expand Up @@ -65,49 +65,52 @@ fn bench_transform(b: &mut Bencher, plugin_dir: &Path) {
#[cfg(feature = "__rkyv")]
b.iter(|| {
GLOBALS.set(&Globals::new(), || {
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));

let fm = cm.new_source_file(
FileName::Real("src/test.ts".into()).into(),
SOURCE.to_string(),
);

let program = parse_file_as_program(
&fm,
Default::default(),
EsVersion::latest(),
None,
&mut Vec::new(),
)
.unwrap();

let program = VersionedSerializable::new(program);
let program_ser = PluginSerializedBytes::try_serialize(&program).unwrap();

let mut transform_plugin_executor = swc_plugin_runner::create_plugin_transform_executor(
&cm,
&Mark::new(),
&Arc::new(TransformPluginMetadataContext::new(
tokio::runtime::Runtime::new().unwrap().block_on(async {
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));

let fm = cm.new_source_file(
FileName::Real("src/test.ts".into()).into(),
SOURCE.to_string(),
);

let program = parse_file_as_program(
&fm,
Default::default(),
EsVersion::latest(),
None,
"development".to_string(),
None,
)),
Box::new(plugin_module.clone()),
None,
None,
);

let experimental_metadata: VersionedSerializable<AHashMap<String, String>> =
VersionedSerializable::new(AHashMap::default());
let _experimental_metadata =
PluginSerializedBytes::try_serialize(&experimental_metadata)
.expect("Should be a hashmap");

let res = transform_plugin_executor
.transform(&program_ser, Some(true))
&mut Vec::new(),
)
.unwrap();

let _ = black_box(res);
let program = VersionedSerializable::new(program);
let program_ser = PluginSerializedBytes::try_serialize(&program).unwrap();

let mut transform_plugin_executor =
swc_plugin_runner::create_plugin_transform_executor(
&cm,
&Mark::new(),
&Arc::new(TransformPluginMetadataContext::new(
None,
"development".to_string(),
None,
)),
Box::new(plugin_module.clone()),
None,
None,
);

let experimental_metadata: VersionedSerializable<AHashMap<String, String>> =
VersionedSerializable::new(AHashMap::default());
let _experimental_metadata =
PluginSerializedBytes::try_serialize(&experimental_metadata)
.expect("Should be a hashmap");

let res = transform_plugin_executor
.transform(&program_ser, Some(true))
.unwrap();

let _ = black_box(res);
});
});
})
}
Expand Down

0 comments on commit b0b5e36

Please sign in to comment.