Improved general performance and performance for animations with large frames.
Why did you make this change?
Performance with resource packs that contain large animation frames was extremely poor (1-2 FPS on my computer with the example presented in #39).
How did you make this change?
Added a new onTick() handler for TextureComponent that is called at least as often as the texture updates with the number of ticks that passed since the last call as the parameter.
Reimplemented the Area class to use longs to avoid unnecessary object creation and memory usage.
Added a method to Area to partition the area into roughly-equally sized "buckets" based on a provided size hint.
Added concurrency support to SparseIntMatrix with read-write locks. A write lock is used whenever a new sector may be allocated or a pixel value is changed. The implementation of SparseIntMatrix was changed to use a single index to access sectors rather than two indices. While this uses more memory, it avoids a more complicated locking scheme and the need to lock large sections of the matrix at the same time.
Changed applyTransform() of CloseableImageFrame to partition large areas and process them on multiple threads.
A cached thread pool reduces overhead from starting many threads. The default thread pool removes threads when they have not been assigned any tasks for 60 seconds.
For areas less than 128 * 128 pixels in size, the current thread is used to avoid unnecessary overhead.
For areas greater than 128 128 pixels in size, the area is partitioned into sub-areas approximately 128 128 pixels in size.
The 128 * 128 value was determined experimentally. Lower values lead to significantly less stability in FPS (presumably due to thread scheduling). Higher values negated the performance improvement of using multiple threads.
How can others see the effect of your change?
Use a resource pack like Hyper Realistic Sky and check the debug menu (F3). The performance hit of such packs should be minor. For this particular pack, you can check performance in three scenarios:
regular gameplay
when a tornado is present at time 126650 in a non-desert biome (/time set 126650)
when auroras are present at time 114000 in a snowy biome (/time set 114000)
Performance with any animated resource pack has also been improved.
Links to related issues
39
Which Minecraft versions does this change apply to?
1.20
Did you test this change on both mod loaders?
[x] Forge
[x] Fabric
Did you unit test this change?
[x] I unit tested this change.
[ ] This change is too small to warrant any new unit tests.
[ ] Other (Please explain below.)
Areas for improvement (if any)
A new TextureComponent handler, onLayerBelowChange, would be useful for plugins that add partially-transparent effects and need to alpha blend pixels in their layer based with pixels updated in layers below.
What did you change?
Improved general performance and performance for animations with large frames.
Why did you make this change?
Performance with resource packs that contain large animation frames was extremely poor (1-2 FPS on my computer with the example presented in #39).
How did you make this change?
onTick()
handler forTextureComponent
that is called at least as often as the texture updates with the number of ticks that passed since the last call as the parameter.Area
class to use longs to avoid unnecessary object creation and memory usage.Area
to partition the area into roughly-equally sized "buckets" based on a provided size hint.SparseIntMatrix
with read-write locks. A write lock is used whenever a new sector may be allocated or a pixel value is changed. The implementation ofSparseIntMatrix
was changed to use a single index to access sectors rather than two indices. While this uses more memory, it avoids a more complicated locking scheme and the need to lock large sections of the matrix at the same time.applyTransform()
ofCloseableImageFrame
to partition large areas and process them on multiple threads.How can others see the effect of your change?
Use a resource pack like Hyper Realistic Sky and check the debug menu (F3). The performance hit of such packs should be minor. For this particular pack, you can check performance in three scenarios:
126650
in a non-desert biome (/time set 126650
)114000
in a snowy biome (/time set 114000
)Performance with any animated resource pack has also been improved.
Links to related issues
39
Which Minecraft versions does this change apply to?
1.20
Did you test this change on both mod loaders?
Did you unit test this change?
Areas for improvement (if any)
A new
TextureComponent
handler,onLayerBelowChange
, would be useful for plugins that add partially-transparent effects and need to alpha blend pixels in their layer based with pixels updated in layers below.Additional notes (if any)
Will be backported to older MC versions.