Commit 48c704cc6331107730089c3680f7191f255bd722
1 parent
a54e9551
Fix some memory consumption issues
Showing
2 changed files
with
17 additions
and
11 deletions
@@ -28,14 +28,18 @@ pub fn launch() -> Sender<(Arc<Pool>, Image)> { | @@ -28,14 +28,18 @@ pub fn launch() -> Sender<(Arc<Pool>, Image)> { | ||
28 | let mut workers = FuturesUnordered::new(); | 28 | let mut workers = FuturesUnordered::new(); |
29 | 29 | ||
30 | loop { | 30 | loop { |
31 | - select! { | ||
32 | - image = rx_upload_worker.recv().fuse() => { | ||
33 | - match image { | ||
34 | - Err(_) => break, | ||
35 | - Ok((pool, image)) => workers.push(worker(pool, image)), | ||
36 | - } | ||
37 | - }, | ||
38 | - _result = workers.next() => {}, | 31 | + if workers.len() <= 3 { |
32 | + select! { | ||
33 | + image = rx_upload_worker.recv().fuse() => { | ||
34 | + match image { | ||
35 | + Err(_) => break, | ||
36 | + Ok((pool, image)) => workers.push(worker(pool, image)), | ||
37 | + } | ||
38 | + }, | ||
39 | + _result = workers.next() => {}, | ||
40 | + } | ||
41 | + } else { | ||
42 | + workers.next().await; | ||
39 | } | 43 | } |
40 | } | 44 | } |
41 | 45 |
@@ -21,8 +21,9 @@ pub(super) async fn upload_preview_logic( mut rx_canvas :broadcast::Receiver<Dom | @@ -21,8 +21,9 @@ pub(super) async fn upload_preview_logic( mut rx_canvas :broadcast::Receiver<Dom | ||
21 | let context = canvas | 21 | let context = canvas |
22 | . get_context("2d").unwrap().unwrap() | 22 | . get_context("2d").unwrap().unwrap() |
23 | . dyn_into::<CanvasRenderingContext2d>().unwrap(); | 23 | . dyn_into::<CanvasRenderingContext2d>().unwrap(); |
24 | - let image_width = upload.bitmap().width() as f64; | ||
25 | - let image_height = upload.bitmap().height() as f64; | 24 | + let bitmap = upload.bitmap(); |
25 | + let image_width = bitmap.width() as f64; | ||
26 | + let image_height = bitmap.height() as f64; | ||
26 | let canvas_width = canvas.width() as f64; | 27 | let canvas_width = canvas.width() as f64; |
27 | let canvas_height = canvas.height() as f64; | 28 | let canvas_height = canvas.height() as f64; |
28 | 29 | ||
@@ -41,9 +42,10 @@ pub(super) async fn upload_preview_logic( mut rx_canvas :broadcast::Receiver<Dom | @@ -41,9 +42,10 @@ pub(super) async fn upload_preview_logic( mut rx_canvas :broadcast::Receiver<Dom | ||
41 | 42 | ||
42 | context | 43 | context |
43 | . draw_image_with_image_bitmap_and_dw_and_dh( | 44 | . draw_image_with_image_bitmap_and_dw_and_dh( |
44 | - &upload.bitmap() | 45 | + &bitmap |
45 | , ox, oy, width, height ) | 46 | , ox, oy, width, height ) |
46 | . unwrap(); | 47 | . unwrap(); |
48 | + bitmap.close(); | ||
47 | } | 49 | } |
48 | } | 50 | } |
49 | 51 |
Please
register
or
login
to post a comment