Commit c84f6c0
authored
refactor(textures): replace defrag system with a slot reuse system (#650)
The defrag system was introduced to avoid endlessly growing the
`this.loadedTextures` however this introduced:
* Additional function calls
* Idle processing
* Potential race conditions when the defrag ran inbetween operations
(like 1 frame idle)
Having a memory allocation with potentially lots of `null` items isn't
going to affect memory usage much. Since we want low-latency, zero-copy,
texture memory placement this PR replaces the defrag system with a Slot
Reuse system.
It simply does:
* On texture delete, `null` the place in the texture array
* On texture creation, pick a previously `null` spot or `append` if
there are none
This avoids potential race conditions and the extra overhead of a
defragmentation system while keeping the textures neatly packed at the
beginning.
The only downside is the `this.loadedTextures` array never shrinks, but
this is deemed neglible because it will be just `null` entries and only
be as large as the largest scene supported while rendering in L3. Which
is a tradeoff against zero copy low latency texture memory allocation.2 files changed
+9
-54
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | 125 | | |
127 | 126 | | |
128 | 127 | | |
| |||
191 | 190 | | |
192 | 191 | | |
193 | 192 | | |
194 | | - | |
| 193 | + | |
195 | 194 | | |
196 | 195 | | |
197 | 196 | | |
198 | | - | |
199 | 197 | | |
200 | 198 | | |
201 | 199 | | |
| |||
204 | 202 | | |
205 | 203 | | |
206 | 204 | | |
207 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
225 | 229 | | |
226 | 230 | | |
227 | 231 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | 232 | | |
242 | 233 | | |
243 | 234 | | |
| |||
250 | 241 | | |
251 | 242 | | |
252 | 243 | | |
253 | | - | |
| 244 | + | |
254 | 245 | | |
255 | 246 | | |
256 | 247 | | |
257 | | - | |
258 | 248 | | |
259 | 249 | | |
260 | 250 | | |
| |||
334 | 324 | | |
335 | 325 | | |
336 | 326 | | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | 327 | | |
369 | 328 | | |
370 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 69 | | |
74 | 70 | | |
75 | 71 | | |
| |||
0 commit comments