refactor(textures): replace defrag system with a slot reuse system #650
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The defrag system was introduced to avoid endlessly growing the
this.loadedTextureshowever this introduced:Having a memory allocation with potentially lots of
nullitems 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:
nullthe place in the texture arraynullspot orappendif there are noneThis 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.loadedTexturesarray never shrinks, but this is deemed neglible because it will be justnullentries 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.