Commit d3705af
authored
perf(web): replace softbuffer with direct put_image_data canvas present (#1374)
## Summary
The web client presented frames through `softbuffer`, whose web backend
repacks
the **whole surface** (RGBA → u32 → RGBA into a fresh buffer) on every
present.
This replaces it with a direct `put_image_data` that uploads only the
dirty
region, and drops the `softbuffer` dependency.
Same idea as the IronVNC change.
## What changed
- Remove the `softbuffer` dependency; present each dirty region with
`put_image_data` at its origin.
- No full-surface buffer and no per-region scratch.
`extract_partial_image` fills
a single `WriteBuf` reused across frames, so steady-state draws don't
allocate.
- Force opaque alpha before upload (kept — see Correctness).
- Add `WriteBuf::filled_mut` to `ironrdp-core` (mutable counterpart of
`filled`).
- `web-sys`: add `CanvasRenderingContext2d` + `ImageData`, drop the
softbuffer-only
features.
## Performance
Draw-stage time on a 1080p replay (595 frames / 110 dirty regions),
headless
Chromium, 8 measured passes × 3 runs, median. Both rows are reproducible
branches
off the replay-bench harness; the only difference is the render path.
| Render path | draw (ms) | vs softbuffer | branch |
|---|--:|--:|---|
| softbuffer `present_with_damage` | ~1031 | — | `bench/draw-softbuffer`
|
| this PR (direct upload, reused `WriteBuf`) | ~97 | **~10.6×** |
`bench/draw-zerocopy` |
- The win is structural: upload the dirty region instead of repacking
the whole
surface every present.
- Reusing one `WriteBuf` (vs a per-frame allocation) keeps the
steady-state draw
allocation-free; the remaining cost is the unavoidable `ImageData` JS
copy.
- Output is **byte-identical**: framebuffer CRC32 `2d8e1b79` matches the
recorded
ground truth and the rendered-canvas FNV-1a is unchanged.
- Absolute ms carry ~±15% noise from machine load (decode drifted
1.5–1.9 s); the
ratio held across runs.
Reproduce:
```sh
git checkout bench/draw-softbuffer # or bench/draw-zerocopy
cd crates/ironrdp-web && wasm-pack build --target web --release -- --features bench
cd bench-harness && node run.mjs --capture /bench-corpus/<your>.irdprec --passes 8
```
## Correctness
`put_image_data` stores alpha verbatim, and the decoded framebuffer
isn't
guaranteed opaque — it's zero-initialised, a widened whole-rows region
can cover
not-yet-painted columns (alpha 0), and the QOI-RGBA path copies source
alpha. So
we force alpha opaque before upload. A scan-then-conditionally-force was
tried and
is *slower* than just forcing (the check touches the same bytes), so the
unconditional force stays.
## Follow-up (separate PR)
Guarantee framebuffer opacity upstream in `ironrdp-session` (init alpha
to `0xff` +
clamp `apply_rgba32`); after that the web side can drop the alpha force
entirely.1 parent 45ec1ef commit d3705af
6 files changed
Lines changed: 108 additions & 93 deletions
File tree
- crates
- ironrdp-core/src
- ironrdp-web
- src
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
55 | 62 | | |
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
59 | 66 | | |
60 | | - | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
8 | 15 | | |
9 | | - | |
10 | | - | |
| 16 | + | |
| 17 | + | |
11 | 18 | | |
12 | 19 | | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
16 | 23 | | |
| 24 | + | |
17 | 25 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
36 | 30 | | |
37 | 31 | | |
| 32 | + | |
| 33 | + | |
38 | 34 | | |
39 | | - | |
40 | | - | |
| 35 | + | |
| 36 | + | |
41 | 37 | | |
42 | 38 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
55 | 45 | | |
| 46 | + | |
56 | 47 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
78 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
79 | 65 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
92 | 81 | | |
93 | 82 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
7 | 14 | | |
8 | 15 | | |
9 | | - | |
| 16 | + | |
10 | 17 | | |
11 | | - | |
| 18 | + | |
12 | 19 | | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
16 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
17 | 28 | | |
18 | 29 | | |
19 | 30 | | |
| |||
26 | 37 | | |
27 | 38 | | |
28 | 39 | | |
29 | | - | |
| 40 | + | |
30 | 41 | | |
31 | 42 | | |
32 | 43 | | |
| |||
42 | 53 | | |
43 | 54 | | |
44 | 55 | | |
45 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
46 | 59 | | |
47 | 60 | | |
48 | 61 | | |
49 | | - | |
| 62 | + | |
50 | 63 | | |
51 | 64 | | |
52 | 65 | | |
| |||
59 | 72 | | |
60 | 73 | | |
61 | 74 | | |
| 75 | + | |
62 | 76 | | |
63 | | - | |
| 77 | + | |
| 78 | + | |
64 | 79 | | |
65 | | - | |
| 80 | + | |
66 | 81 | | |
67 | 82 | | |
68 | 83 | | |
69 | 84 | | |
70 | | - | |
71 | | - | |
72 | | - | |
| 85 | + | |
73 | 86 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
657 | 657 | | |
658 | 658 | | |
659 | 659 | | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
660 | 663 | | |
661 | 664 | | |
662 | 665 | | |
| |||
875 | 878 | | |
876 | 879 | | |
877 | 880 | | |
878 | | - | |
879 | | - | |
880 | | - | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
881 | 885 | | |
882 | 886 | | |
883 | 887 | | |
| |||
987 | 991 | | |
988 | 992 | | |
989 | 993 | | |
990 | | - | |
991 | | - | |
992 | 994 | | |
993 | 995 | | |
994 | 996 | | |
| |||
0 commit comments