This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Commit 2d56e44
authored
[web:canvaskit] switch to temporary SkPaint objects (#54818)
Do not eagerly create an `SkPaint` object that's strongly referenced by `CkPaint`. Instead, when a `Canvas.draw*` is called, create a temporary `SkPaint` object, pass it to Skia, then immediately delete it. This way there are no persistent `SkPaint` handles lurking in the system that transitively hold onto expensive native resources.
Addresses the `Paint` issue in flutter/flutter#153678 in CanvasKit
Spot checking some benchmarks. Here's the effect of this PR on `draw_rect_variable_paint`. It's a bit of a stress test as it creates 300K distinct `Paint` objects to render 600 pictures (a typical ratio does not normally exceed ten paints to one picture). Even so, the effect of creating an extra `SkPaint` on every `draw*` command does not look significant. However, removing a dependency on the GC for 300K objects looks like a good trade-off.
## Before
Allocation stats:
```
Paint Created: 300000
Paint Deleted: 300000
Paint Leaked: 300000
Picture Created: 600
Picture Deleted: 599
Picture Leaked: 599
```
Performance stats:
```
windowRenderDuration: (samples: 98 clean/2 outliers/100 measured/300 total)
| average: 4679.551020408163 μs
| outlier average: 5100 μs
| outlier/clean ratio: 1.0898481452084188x
| noise: 3.11%
sceneBuildDuration: (samples: 98 clean/2 outliers/100 measured/300 total)
| average: 4689.765306122449 μs
| outlier average: 5100 μs
| outlier/clean ratio: 1.087474461321549x
| noise: 3.19%
drawFrameDuration: (samples: 97 clean/3 outliers/100 measured/300 total)
| average: 8447.474226804125 μs
| outlier average: 9332.666666666666 μs
| outlier/clean ratio: 1.1047878236850721x
| noise: 3.52%
```
## After
Allocation stats:
```
Picture Created: 600
Picture Deleted: 599
Picture Leaked: 599
```
Performance stats:
```
windowRenderDuration: (samples: 97 clean/3 outliers/100 measured/300 total)
| average: 4780.40206185567 μs
| outlier average: 5133.666666666667 μs
| outlier/clean ratio: 1.0738985131877936x
| noise: 2.70%
sceneBuildDuration: (samples: 97 clean/3 outliers/100 measured/300 total)
| average: 4787.6082474226805 μs
| outlier average: 5133.666666666667 μs
| outlier/clean ratio: 1.0722821085936345x
| noise: 2.72%
drawFrameDuration: (samples: 97 clean/3 outliers/100 measured/300 total)
| average: 8243.309278350516 μs
| outlier average: 9033.333333333334 μs
| outlier/clean ratio: 1.0958382159768851x
| noise: 2.60%
```1 parent 4f1de98 commit 2d56e44
File tree
14 files changed
+280
-347
lines changed- lib/web_ui
- lib
- src/engine
- canvaskit
- html
- test
- canvaskit
- ui
14 files changed
+280
-347
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | 328 | | |
337 | 329 | | |
338 | 330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
88 | | - | |
| 90 | + | |
89 | 91 | | |
| 92 | + | |
90 | 93 | | |
91 | 94 | | |
92 | 95 | | |
| |||
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
104 | 108 | | |
105 | | - | |
| 109 | + | |
106 | 110 | | |
107 | 111 | | |
108 | 112 | | |
| 113 | + | |
109 | 114 | | |
110 | 115 | | |
111 | 116 | | |
| 117 | + | |
112 | 118 | | |
113 | 119 | | |
114 | 120 | | |
115 | 121 | | |
116 | | - | |
| 122 | + | |
117 | 123 | | |
| 124 | + | |
118 | 125 | | |
119 | 126 | | |
120 | 127 | | |
| |||
125 | 132 | | |
126 | 133 | | |
127 | 134 | | |
| 135 | + | |
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
131 | | - | |
| 139 | + | |
132 | 140 | | |
| 141 | + | |
133 | 142 | | |
134 | 143 | | |
135 | 144 | | |
136 | 145 | | |
| 146 | + | |
137 | 147 | | |
138 | 148 | | |
139 | 149 | | |
140 | 150 | | |
141 | 151 | | |
142 | 152 | | |
143 | 153 | | |
144 | | - | |
| 154 | + | |
145 | 155 | | |
146 | 156 | | |
147 | 157 | | |
| |||
150 | 160 | | |
151 | 161 | | |
152 | 162 | | |
153 | | - | |
| 163 | + | |
154 | 164 | | |
155 | 165 | | |
| 166 | + | |
156 | 167 | | |
157 | 168 | | |
158 | 169 | | |
159 | 170 | | |
| 171 | + | |
160 | 172 | | |
161 | 173 | | |
162 | 174 | | |
163 | 175 | | |
164 | 176 | | |
165 | 177 | | |
166 | 178 | | |
167 | | - | |
| 179 | + | |
168 | 180 | | |
169 | 181 | | |
170 | 182 | | |
| |||
173 | 185 | | |
174 | 186 | | |
175 | 187 | | |
176 | | - | |
| 188 | + | |
177 | 189 | | |
178 | 190 | | |
| 191 | + | |
179 | 192 | | |
180 | 193 | | |
181 | 194 | | |
182 | 195 | | |
| 196 | + | |
183 | 197 | | |
184 | 198 | | |
185 | 199 | | |
186 | 200 | | |
187 | 201 | | |
188 | | - | |
| 202 | + | |
189 | 203 | | |
| 204 | + | |
190 | 205 | | |
191 | 206 | | |
192 | 207 | | |
| 208 | + | |
193 | 209 | | |
194 | 210 | | |
195 | 211 | | |
196 | 212 | | |
197 | 213 | | |
198 | | - | |
| 214 | + | |
199 | 215 | | |
| 216 | + | |
200 | 217 | | |
201 | 218 | | |
202 | 219 | | |
| 220 | + | |
203 | 221 | | |
204 | 222 | | |
205 | | - | |
| 223 | + | |
206 | 224 | | |
| 225 | + | |
207 | 226 | | |
208 | 227 | | |
209 | 228 | | |
210 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
211 | 232 | | |
212 | 233 | | |
213 | 234 | | |
| |||
219 | 240 | | |
220 | 241 | | |
221 | 242 | | |
222 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
223 | 246 | | |
224 | 247 | | |
225 | 248 | | |
| |||
228 | 251 | | |
229 | 252 | | |
230 | 253 | | |
| 254 | + | |
231 | 255 | | |
232 | 256 | | |
233 | 257 | | |
234 | | - | |
| 258 | + | |
235 | 259 | | |
| 260 | + | |
236 | 261 | | |
237 | 262 | | |
238 | 263 | | |
| 264 | + | |
239 | 265 | | |
240 | 266 | | |
241 | | - | |
| 267 | + | |
242 | 268 | | |
| 269 | + | |
243 | 270 | | |
244 | 271 | | |
245 | 272 | | |
246 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
247 | 276 | | |
248 | 277 | | |
249 | 278 | | |
| |||
254 | 283 | | |
255 | 284 | | |
256 | 285 | | |
| 286 | + | |
257 | 287 | | |
258 | 288 | | |
259 | 289 | | |
260 | | - | |
| 290 | + | |
261 | 291 | | |
| 292 | + | |
262 | 293 | | |
263 | 294 | | |
264 | 295 | | |
| |||
278 | 309 | | |
279 | 310 | | |
280 | 311 | | |
| 312 | + | |
281 | 313 | | |
282 | | - | |
| 314 | + | |
283 | 315 | | |
284 | 316 | | |
285 | 317 | | |
286 | 318 | | |
| 319 | + | |
287 | 320 | | |
288 | 321 | | |
289 | 322 | | |
290 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
291 | 326 | | |
292 | 327 | | |
293 | 328 | | |
| |||
298 | 333 | | |
299 | 334 | | |
300 | 335 | | |
301 | | - | |
| 336 | + | |
| 337 | + | |
302 | 338 | | |
303 | | - | |
| 339 | + | |
304 | 340 | | |
305 | 341 | | |
306 | 342 | | |
307 | 343 | | |
| 344 | + | |
308 | 345 | | |
309 | 346 | | |
310 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1516 | 1516 | | |
1517 | 1517 | | |
1518 | 1518 | | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
1519 | 1522 | | |
1520 | 1523 | | |
1521 | 1524 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
304 | 303 | | |
305 | 304 | | |
306 | 305 | | |
| |||
0 commit comments