Skip to content

Commit

Permalink
Merge pull request #25 from persevie/feature/parallel-execution-impro…
Browse files Browse the repository at this point in the history
…vements

Parallel Execution Improvements
  • Loading branch information
dmtrshat authored Nov 5, 2024
2 parents 688c61b + 5c2af43 commit c3bd10b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ indicatif = "0.17.8"
lazy_static = "1.5.0"
lightningcss = { version = "1.0.0-alpha.59", features = ["browserslist"] }
once_cell = "1.20"
rayon = "1.10.0"
regex = "1.11.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
36 changes: 7 additions & 29 deletions src/core/css_builder.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//! Provides the `CSSBuilder` struct and its associated methods for compiling and building CSS files based on a configuration.

use crate::buffer::add_message;

use super::{
build_info::BuildInfo, css_generator::CSSGenerator, css_optimizer::CSSOptimizer,
parser::Parser, spell::Spell, Config, ConfigCSSCustomProperties, GrimoireCSSError,
};
use rayon::prelude::*;
use crate::buffer::add_message;
use regex::Regex;
use std::{
collections::HashSet,
Expand Down Expand Up @@ -166,18 +164,9 @@ impl<'a> CSSBuilder<'a> {
///
/// Returns a `GrimoireCSSError` if writing to files fails.
fn write_compiled_css(compiled_css: Vec<(PathBuf, String)>) -> Result<(), GrimoireCSSError> {
if compiled_css.len() > 10 {
// Use parallelism if there are multiple files
compiled_css.par_iter().try_for_each(|(file_path, css)| {
Self::create_output_directory_if_needed(file_path)?;
fs::write(file_path, css).map_err(GrimoireCSSError::from)
})?;
} else {
// Process sequentially if there's only one file
for (file_path, css) in compiled_css {
Self::create_output_directory_if_needed(&file_path)?;
fs::write(file_path, css)?;
}
for (file_path, css) in compiled_css {
Self::create_output_directory_if_needed(&file_path)?;
fs::write(file_path, css)?;
}

Ok(())
Expand Down Expand Up @@ -481,20 +470,9 @@ impl<'a> CSSBuilder<'a> {
&self,
inline_shared_css: &Vec<(PathBuf, String)>,
) -> Result<(), GrimoireCSSError> {
if inline_shared_css.len() > 10 {
// Use parallelism if there are multiple HTML files
inline_shared_css
.par_iter()
.try_for_each(|(file_path, css)| {
let path = self.current_dir.join(file_path);
self.embed_critical_css(&path, css)
})?;
} else {
// Process sequentially if there's only one HTML file
for (file_path, css) in inline_shared_css {
let path = self.current_dir.join(file_path);
self.embed_critical_css(&path, css)?;
}
for (file_path, css) in inline_shared_css {
let path = self.current_dir.join(file_path);
self.embed_critical_css(&path, css)?;
}

Ok(())
Expand Down

0 comments on commit c3bd10b

Please sign in to comment.