Skip to content

Conversation

@wouterlucas
Copy link
Contributor

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.

@wouterlucas wouterlucas requested a review from jfboeve October 2, 2025 20:12
@wouterlucas wouterlucas merged commit c84f6c0 into v2 Oct 6, 2025
2 checks passed
@wouterlucas wouterlucas deleted the fix/remove-defrag branch October 6, 2025 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants