mirror of
https://github.com/swc-project/swc.git
synced 2024-11-26 09:54:22 +03:00
perf(css/minifier): Setup benchmark (#5800)
**Description:** I created a simple benchmark for the css minifier. It's full benchmark, which also profiles parser and codegen
This commit is contained in:
parent
a94d9f1fbd
commit
88e59ffcda
16
.github/workflows/stale.yml
vendored
16
.github/workflows/stale.yml
vendored
@ -1,9 +1,9 @@
|
||||
name: 'Stale issue handler'
|
||||
name: "Stale issue handler"
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# This runs every day 20 minutes before midnight: https://crontab.guru/#40_23_*_*_*
|
||||
- cron: '40 23 * * *'
|
||||
- cron: "40 23 * * *"
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
@ -12,14 +12,14 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/stale@v4
|
||||
id: stale
|
||||
name: 'Close stale issues with no reproduction'
|
||||
name: "Close stale issues with no reproduction"
|
||||
with:
|
||||
repo-token: ${{ secrets.GH_TOKEN }}
|
||||
only-labels: 'Need more info'
|
||||
close-issue-message: 'This issue has been automatically closed because it received no activity for a month and had no reproduction to investigate. If you think this was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you.'
|
||||
only-labels: "Need more info"
|
||||
close-issue-message: "This issue has been automatically closed because it received no activity for a month and had no reproduction to investigate. If you think this was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you."
|
||||
days-before-issue-close: 1
|
||||
days-before-issue-stale: 30
|
||||
days-before-issue-stale: 5
|
||||
days-before-pr-close: -1
|
||||
days-before-pr-stale: -1
|
||||
exempt-issue-labels: 'blocked,must,should,keep'
|
||||
operations-per-run: 300 # 1 operation per 100 issues, the rest is to label/comment/close
|
||||
exempt-issue-labels: "blocked,must,should,keep"
|
||||
operations-per-run: 300 # 1 operation per 100 issues, the rest is to label/comment/close
|
||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3231,6 +3231,7 @@ dependencies = [
|
||||
name = "swc_css_minifier"
|
||||
version = "0.86.0"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"serde",
|
||||
"swc_atoms",
|
||||
"swc_common",
|
||||
@ -3239,6 +3240,7 @@ dependencies = [
|
||||
"swc_css_parser",
|
||||
"swc_css_utils",
|
||||
"swc_css_visit",
|
||||
"swc_node_base",
|
||||
"testing",
|
||||
]
|
||||
|
||||
|
@ -21,6 +21,12 @@ swc_css_utils = { version = "0.108.0", path = "../swc_css_utils/" }
|
||||
swc_css_visit = { version = "0.110.0", path = "../swc_css_visit" }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
swc_css_codegen = { version = "0.121.0", path = "../swc_css_codegen" }
|
||||
swc_css_parser = { version = "0.120.0", path = "../swc_css_parser" }
|
||||
swc_node_base = { version = "0.5.0", path = "../swc_node_base" }
|
||||
testing = { version = "0.30.0", path = "../testing" }
|
||||
|
||||
[[bench]]
|
||||
harness = false
|
||||
name = "full"
|
||||
|
78
crates/swc_css_minifier/benches/full.rs
Normal file
78
crates/swc_css_minifier/benches/full.rs
Normal file
@ -0,0 +1,78 @@
|
||||
extern crate swc_node_base;
|
||||
|
||||
use std::{fs::read_to_string, path::Path};
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use swc_common::{errors::HANDLER, FileName};
|
||||
use swc_css_ast::Stylesheet;
|
||||
use swc_css_codegen::{
|
||||
writer::basic::{BasicCssWriter, BasicCssWriterConfig},
|
||||
Emit,
|
||||
};
|
||||
use swc_css_minifier::minify;
|
||||
use swc_css_parser::{parse_file, parser::ParserConfig};
|
||||
|
||||
pub fn bench_files(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("es/minify/libraries");
|
||||
group.sample_size(10);
|
||||
|
||||
let mut bench_file = |name: &str, path: &Path| {
|
||||
let src = read_to_string(path).unwrap();
|
||||
|
||||
group.bench_function(name, |b| {
|
||||
b.iter(|| {
|
||||
// We benchmark full time, including time for creating cm, handler
|
||||
run(&src)
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
bench_file(
|
||||
"bootstrap",
|
||||
Path::new("../../node_modules/bootstrap/dist/css/bootstrap.css"),
|
||||
);
|
||||
}
|
||||
|
||||
criterion_group!(files, bench_files);
|
||||
criterion_main!(files);
|
||||
|
||||
fn run(src: &str) {
|
||||
testing::run_test2(false, |cm, handler| {
|
||||
HANDLER.set(&handler, || {
|
||||
let fm = cm.new_source_file(FileName::Anon, src.into());
|
||||
|
||||
let mut errors = vec![];
|
||||
let mut ss: Stylesheet = parse_file(
|
||||
&fm,
|
||||
ParserConfig {
|
||||
..Default::default()
|
||||
},
|
||||
&mut errors,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
minify(&mut ss, Default::default());
|
||||
|
||||
let mut buf = String::new();
|
||||
{
|
||||
let wr = BasicCssWriter::new(
|
||||
&mut buf,
|
||||
None,
|
||||
BasicCssWriterConfig {
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let mut generator = swc_css_codegen::CodeGenerator::new(
|
||||
wr,
|
||||
swc_css_codegen::CodegenConfig { minify: true },
|
||||
);
|
||||
|
||||
generator.emit(&ss).unwrap();
|
||||
}
|
||||
|
||||
black_box(buf);
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
}
|
11
crates/swc_css_minifier/scripts/instrument/bench-full.sh
Executable file
11
crates/swc_css_minifier/scripts/instrument/bench-full.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This instruments a full benchmark suite.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# ./scripts/instrument/bench.sh typescript
|
||||
|
||||
|
||||
export RUST_LOG=off
|
||||
cargo profile instruments -t time --bench full --release -- $@
|
@ -109,6 +109,7 @@
|
||||
"axios": "^0.21.1",
|
||||
"babel-plugin-transform-node-env-inline": "^0.4.3",
|
||||
"benchmark": "^2.1.4",
|
||||
"bootstrap": "^5.2.1",
|
||||
"class-validator": "^0.13.1",
|
||||
"core-js": "^2.6.11",
|
||||
"core-js-compat": "^3.21.1",
|
||||
@ -177,4 +178,4 @@
|
||||
"postinstall.js",
|
||||
"bindings/binding_core_wasm/pkg/binding_core_wasm.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
10
yarn.lock
10
yarn.lock
@ -2353,6 +2353,7 @@ __metadata:
|
||||
axios: ^0.21.1
|
||||
babel-plugin-transform-node-env-inline: ^0.4.3
|
||||
benchmark: ^2.1.4
|
||||
bootstrap: ^5.2.1
|
||||
class-validator: ^0.13.1
|
||||
core-js: ^2.6.11
|
||||
core-js-compat: ^3.21.1
|
||||
@ -2992,6 +2993,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"bootstrap@npm:^5.2.1":
|
||||
version: 5.2.1
|
||||
resolution: "bootstrap@npm:5.2.1"
|
||||
peerDependencies:
|
||||
"@popperjs/core": ^2.11.6
|
||||
checksum: f7d733ae5d27177d813adb2ac2158f08069a558d8f664b3db8857aba0ab07423d83b4276dba6123dde52309e707bb06ec13e040fb905eaa293c53453110bb802
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"brace-expansion@npm:^1.1.7":
|
||||
version: 1.1.11
|
||||
resolution: "brace-expansion@npm:1.1.11"
|
||||
|
Loading…
Reference in New Issue
Block a user