diff --git a/Cargo.lock b/Cargo.lock index 76192a3f..c390068d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2484,6 +2484,7 @@ dependencies = [ "ironrdp-rdpsnd", "ironrdp-svc", "ironrdp-tokio", + "rayon", "rustls-pemfile", "tokio", "tokio-rustls", diff --git a/crates/ironrdp-server/Cargo.toml b/crates/ironrdp-server/Cargo.toml index 0750f926..2bc3fb23 100644 --- a/crates/ironrdp-server/Cargo.toml +++ b/crates/ironrdp-server/Cargo.toml @@ -16,7 +16,9 @@ doctest = true test = false [features] +default = ["rayon"] helper = ["dep:x509-cert", "dep:rustls-pemfile"] +rayon = ["dep:rayon"] # Internal (PRIVATE!) features used to aid testing. # Don't rely on these whatsoever. They may disappear at any time. @@ -42,6 +44,7 @@ ironrdp-rdpsnd.workspace = true tracing.workspace = true x509-cert = { version = "0.2.5", optional = true } rustls-pemfile = { version = "2.2.0", optional = true } +rayon = { version = "1.10.0", optional = true } [dev-dependencies] tokio = { version = "1", features = ["sync"] } diff --git a/crates/ironrdp-server/src/encoder/rfx.rs b/crates/ironrdp-server/src/encoder/rfx.rs index 2292b2cf..6324f9e9 100644 --- a/crates/ironrdp-server/src/encoder/rfx.rs +++ b/crates/ironrdp-server/src/encoder/rfx.rs @@ -144,9 +144,16 @@ impl<'a> UpdateEncoder<'a> { } fn encode(&self, data: &'a mut UpdateEncoderData) -> EncodeResult>> { + #[cfg(feature = "rayon")] + use rayon::prelude::*; + let (tiles_x, tiles_y) = self.tiles_xy(); + #[cfg(not(feature = "rayon"))] let chunks = data.0.chunks_mut(64 * 64 * 3); + #[cfg(feature = "rayon")] + let chunks = data.0.par_chunks_mut(64 * 64 * 3); + let tiles: Vec<_> = (0..tiles_y).flat_map(|y| (0..tiles_x).map(move |x| (x, y))).collect(); chunks