perf(transcode): eliminate double buffer copy by accepting Bytes instead of &[u8]
Change ImageTranscodePort::get_transcoded signature from &[u8] to Bytes. - Rayon closure now receives Bytes::clone() (O(1) ref-count) instead of .to_vec() (~5 MB copy) - Fallback path returns owned Bytes directly instead of Bytes::from(to_vec()) (~5 MB copy) - Caller passes content.clone() (O(1)) instead of implicit deref Saves ~10 MB of allocation per transcode call on a 5 MB image.
This commit is contained in:
@@ -90,7 +90,7 @@ pub trait ImageTranscodePort: Send + Sync + 'static {
|
||||
async fn get_transcoded(
|
||||
&self,
|
||||
file_id: &str,
|
||||
original_content: &[u8],
|
||||
original_content: Bytes,
|
||||
original_mime: &str,
|
||||
target_format: OutputFormat,
|
||||
) -> Result<(Bytes, String, bool), DomainError>;
|
||||
|
||||
@@ -88,7 +88,7 @@ impl FileRetrievalService {
|
||||
return None;
|
||||
}
|
||||
let format = OutputFormat::WebP;
|
||||
match transcode.get_transcoded(id, content, mime, format).await {
|
||||
match transcode.get_transcoded(id, content.clone(), mime, format).await {
|
||||
Ok((transcoded, webp_mime, true)) => {
|
||||
debug!(
|
||||
"🖼️ WebP transcode: {} -> {} bytes ({:.0}% smaller)",
|
||||
|
||||
Reference in New Issue
Block a user