Skip to content

Commit

Permalink
Use rayon to speedup codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
morr0ne committed Nov 23, 2024
1 parent 1677865 commit 08ffd2f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
52 changes: 52 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/verdiwm/waynest"
include = ["src/**/*.rs", "../README.md", "../LICENSE"]

[features]
bin = ["dep:anyhow", "dep:clap", "dep:tracing-subscriber"]
bin = ["dep:anyhow", "dep:clap", "dep:tracing-subscriber", "dep:rayon"]

[dependencies]
thiserror = "2.0.3"
Expand All @@ -29,6 +29,7 @@ clap = { version = "4.5.21", optional = true, features = ["derive"] }
tracing-subscriber = { version = "0.3.18", optional = true, features = [
"env-filter",
] }
rayon = { version = "1.10.0", optional = true }

[[bin]]
name = "waynest-gen"
Expand Down
15 changes: 10 additions & 5 deletions gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use clap::Parser;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::{collections::HashMap, fmt::Write as _, fs::OpenOptions, io::Write as _};
use tracing::info;

Expand Down Expand Up @@ -49,16 +50,18 @@ fn main() -> Result<()> {
} else {
let mut module_content = "pub mod core;".to_string();

for (module, current) in protocols {
if module != "core" {
for (module, _current) in &protocols {
if module.as_str() != "core" {
writeln!(
&mut module_content,
r#"#[cfg(feature = "{module}")]
#[cfg_attr(docsrs, doc(cfg(feature = "{module}")))]
pub mod {module};"#
#[cfg_attr(docsrs, doc(cfg(feature = "{module}")))]
pub mod {module};"#
)?;
}
}

protocols.par_iter().try_for_each(|(module, current)| {
let mut server_path = OpenOptions::new()
.truncate(true)
.write(true)
Expand All @@ -82,7 +85,9 @@ pub mod {module};"#
"{}",
generate_client_code(&current, &pairs)
)?;
}

anyhow::Ok(())
})?;

let mut server_module = OpenOptions::new()
.truncate(true)
Expand Down

0 comments on commit 08ffd2f

Please sign in to comment.