From 3b294dde05a6592545e76dc595b80e5ae0a64fe4 Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Tue, 29 Aug 2023 13:20:37 +0800 Subject: [PATCH] fix: ci (#523) * fix: lint * fix: merge error * fix: build warning * feat: update bench result render * chore: clippy fix --- Cargo.lock | 1 + libs/jwst-codec-util/Cargo.toml | 17 ++- .../bin/bench_result_render.rs | 121 ++++++++++++++++++ libs/jwst-codec/src/doc/types/map.rs | 2 +- libs/jwst-codec/src/doc/types/mod.rs | 2 + libs/jwst-storage/src/migration/src/lib.rs | 2 +- .../m20220101_000001_initial_blob_table.rs | 2 +- .../src/m20220101_000002_initial_doc_table.rs | 2 +- .../m20230321_000001_blob_optimized_table.rs | 2 +- ...230614_000001_initial_bucket_blob_table.rs | 2 +- .../src/m20230626_023319_doc_guid.rs | 2 +- .../migration/src/{schema.rs => schemas.rs} | 0 12 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 libs/jwst-codec-util/bin/bench_result_render.rs rename libs/jwst-storage/src/migration/src/{schema.rs => schemas.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index 5186bb2f..09f324c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2740,6 +2740,7 @@ dependencies = [ "arbitrary", "jwst-codec", "phf", + "regex", "yrs", ] diff --git a/libs/jwst-codec-util/Cargo.toml b/libs/jwst-codec-util/Cargo.toml index 42ea4948..050b8df0 100644 --- a/libs/jwst-codec-util/Cargo.toml +++ b/libs/jwst-codec-util/Cargo.toml @@ -5,8 +5,17 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +bench = ["regex"] +fuzz = ["arbitrary", "jwst-codec", "phf", "yrs"] + [dependencies] -arbitrary = { version = "1.3.0", features = ["derive"] } -phf = { version = "0.11", features = ["macros"] } -yrs = "0.16.5" -jwst-codec = { workspace = true } +arbitrary = { version = "1.3.0", features = ["derive"], optional = true } +jwst-codec = { workspace = true, optional = true } +phf = { version = "0.11", features = ["macros"], optional = true } +regex = { version = "1.5", optional = true } +yrs = { version = "=0.16.5", optional = true } + +[[bin]] +name = "bench_result_render" +path = "bin/bench_result_render.rs" diff --git a/libs/jwst-codec-util/bin/bench_result_render.rs b/libs/jwst-codec-util/bin/bench_result_render.rs new file mode 100644 index 00000000..b47f1e1c --- /dev/null +++ b/libs/jwst-codec-util/bin/bench_result_render.rs @@ -0,0 +1,121 @@ +use std::{ + collections::HashMap, + io::{self, BufRead}, +}; + +fn process_duration(duration: &str) -> Option<(f64, f64)> { + let dur_split: Vec = duration.split('±').map(String::from).collect(); + if dur_split.len() != 2 { + return None; + } + let units = dur_split[1] + .chars() + .skip_while(|c| c.is_ascii_digit()) + .collect::(); + let dur_secs = dur_split[0].parse::().ok()?; + let error_secs = dur_split[1] + .chars() + .take_while(|c| c.is_ascii_digit()) + .collect::() + .parse::() + .ok()?; + Some(( + convert_dur_to_seconds(dur_secs, &units), + convert_dur_to_seconds(error_secs, &units), + )) +} + +fn convert_dur_to_seconds(dur: f64, units: &str) -> f64 { + let factors: HashMap<_, _> = [ + ("s", 1.0), + ("ms", 1.0 / 1000.0), + ("µs", 1.0 / 1_000_000.0), + ("ns", 1.0 / 1_000_000_000.0), + ] + .iter() + .cloned() + .collect(); + dur * factors.get(units).unwrap_or(&1.0) +} + +fn is_significant(changes_dur: f64, changes_err: f64, base_dur: f64, base_err: f64) -> bool { + if changes_dur < base_dur { + changes_dur + changes_err < base_dur || base_dur - base_err > changes_dur + } else { + changes_dur - changes_err > base_dur || base_dur + base_err < changes_dur + } +} + +fn convert_to_markdown() -> impl Iterator { + #[cfg(feature = "bench")] + let re = regex::Regex::new(r"\s{2,}").unwrap(); + io::stdin() + .lock() + .lines() + .skip(2) + .flat_map(move |row| { + if let Ok(_row) = row { + let columns = { + #[cfg(feature = "bench")] + { + re.split(&_row).collect::>() + } + #[cfg(not(feature = "bench"))] + Vec::<&str>::new() + }; + let name = columns.first()?; + let base_duration = columns.get(2)?; + let changes_duration = columns.get(5)?; + Some(( + name.to_string(), + base_duration.to_string(), + changes_duration.to_string(), + )) + } else { + None + } + }) + .flat_map(|(name, base_duration, changes_duration)| { + let mut difference = "N/A".to_string(); + let base_undefined = base_duration == "?"; + let changes_undefined = changes_duration == "?"; + + if !base_undefined && !changes_undefined { + let (base_dur_secs, base_err_secs) = process_duration(&base_duration)?; + let (changes_dur_secs, changes_err_secs) = process_duration(&changes_duration)?; + + let diff = -(1.0 - changes_dur_secs / base_dur_secs) * 100.0; + difference = format!("{:+.2}%", diff); + + if is_significant(changes_dur_secs, changes_err_secs, base_dur_secs, base_err_secs) { + difference = format!("**{}**", difference); + } + } + + Some(format!( + "| {} | {} | {} | {} |", + name.replace('|', "\\|"), + if base_undefined { "N/A" } else { &base_duration }, + if changes_undefined { "N/A" } else { &changes_duration }, + difference + )) + }) +} + +fn main() { + let platform = std::env::args().nth(1).expect("Missing platform argument"); + + let headers = vec![ + format!("## Benchmark for {}", platform), + "
".to_string(), + " Click to view benchmark".to_string(), + "".to_string(), + "| Test | Base | PR | % |".to_string(), + "| --- | --- | --- | --- |".to_string(), + ]; + + for line in headers.into_iter().chain(convert_to_markdown()) { + println!("{}", line); + } + println!("
"); +} diff --git a/libs/jwst-codec/src/doc/types/map.rs b/libs/jwst-codec/src/doc/types/map.rs index de34ee50..941196ea 100644 --- a/libs/jwst-codec/src/doc/types/map.rs +++ b/libs/jwst-codec/src/doc/types/map.rs @@ -113,7 +113,7 @@ pub(crate) trait MapType: AsInner { }); MapIterator { - nodes: map.unwrap_or(vec![]), + nodes: map.unwrap_or_default(), index: 0, } } diff --git a/libs/jwst-codec/src/doc/types/mod.rs b/libs/jwst-codec/src/doc/types/mod.rs index a4ee9021..e6e2a27e 100644 --- a/libs/jwst-codec/src/doc/types/mod.rs +++ b/libs/jwst-codec/src/doc/types/mod.rs @@ -105,6 +105,7 @@ impl YTypeRef { self.inner.get().and_then(|ty| ty.write().ok()) } + #[allow(dead_code)] pub fn store<'a>(&self) -> Option> { if let Some(store) = self.store.upgrade() { let ptr = unsafe { &*Arc::as_ptr(&store) }; @@ -125,6 +126,7 @@ impl YTypeRef { } } + #[allow(dead_code)] pub fn read(&self) -> Option<(RwLockReadGuard, RwLockReadGuard)> { self.store().and_then(|store| self.ty().map(|ty| (store, ty))) } diff --git a/libs/jwst-storage/src/migration/src/lib.rs b/libs/jwst-storage/src/migration/src/lib.rs index b2b885e8..8861c8ec 100644 --- a/libs/jwst-storage/src/migration/src/lib.rs +++ b/libs/jwst-storage/src/migration/src/lib.rs @@ -6,7 +6,7 @@ mod m20230321_000001_blob_optimized_table; mod m20230614_000001_initial_bucket_blob_table; mod m20230626_023319_doc_guid; mod m20230814_061223_initial_diff_log_table; -mod schema; +mod schemas; pub struct Migrator; diff --git a/libs/jwst-storage/src/migration/src/m20220101_000001_initial_blob_table.rs b/libs/jwst-storage/src/migration/src/m20220101_000001_initial_blob_table.rs index f253f697..f6b4e518 100644 --- a/libs/jwst-storage/src/migration/src/m20220101_000001_initial_blob_table.rs +++ b/libs/jwst-storage/src/migration/src/m20220101_000001_initial_blob_table.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use super::schema::Blobs; +use super::schemas::Blobs; pub struct Migration; diff --git a/libs/jwst-storage/src/migration/src/m20220101_000002_initial_doc_table.rs b/libs/jwst-storage/src/migration/src/m20220101_000002_initial_doc_table.rs index 47edd048..c357701e 100644 --- a/libs/jwst-storage/src/migration/src/m20220101_000002_initial_doc_table.rs +++ b/libs/jwst-storage/src/migration/src/m20220101_000002_initial_doc_table.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use super::schema::Docs; +use super::schemas::Docs; pub struct Migration; diff --git a/libs/jwst-storage/src/migration/src/m20230321_000001_blob_optimized_table.rs b/libs/jwst-storage/src/migration/src/m20230321_000001_blob_optimized_table.rs index d89fab85..8f9676dd 100644 --- a/libs/jwst-storage/src/migration/src/m20230321_000001_blob_optimized_table.rs +++ b/libs/jwst-storage/src/migration/src/m20230321_000001_blob_optimized_table.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use super::schema::OptimizedBlobs; +use super::schemas::OptimizedBlobs; pub struct Migration; diff --git a/libs/jwst-storage/src/migration/src/m20230614_000001_initial_bucket_blob_table.rs b/libs/jwst-storage/src/migration/src/m20230614_000001_initial_bucket_blob_table.rs index 3f778d8c..ceb35c57 100644 --- a/libs/jwst-storage/src/migration/src/m20230614_000001_initial_bucket_blob_table.rs +++ b/libs/jwst-storage/src/migration/src/m20230614_000001_initial_bucket_blob_table.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use super::schema::BucketBlobs; +use super::schemas::BucketBlobs; pub struct Migration; diff --git a/libs/jwst-storage/src/migration/src/m20230626_023319_doc_guid.rs b/libs/jwst-storage/src/migration/src/m20230626_023319_doc_guid.rs index bfe91e36..ccaf1f49 100644 --- a/libs/jwst-storage/src/migration/src/m20230626_023319_doc_guid.rs +++ b/libs/jwst-storage/src/migration/src/m20230626_023319_doc_guid.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use crate::schema::Docs; +use crate::schemas::Docs; #[derive(DeriveMigrationName)] pub struct Migration; diff --git a/libs/jwst-storage/src/migration/src/schema.rs b/libs/jwst-storage/src/migration/src/schemas.rs similarity index 100% rename from libs/jwst-storage/src/migration/src/schema.rs rename to libs/jwst-storage/src/migration/src/schemas.rs