feat: Optimization in sprite batch #2861
Merged
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.
Description
After a chat with the flutter team responsible for the rendering engine, I've learned that we don't need to pass a blend mode and colors for the
drawAtlas
call is those colors/blending will not generate any real change in the rendered result.On
SpriteBatch
by default we add a full transparent color for all the rects in the batch, that blending makes no difference in the final rendered call since it is a transparent color, so we were adding unnecessary processing in the calls.This PR changes
SpriteBatch
in a way that is had no default blending color and it will just pass those colors todrawAtlas
if the developer has explicit informed a default color or a color in the render.I made a quick benchmark and this optimization is minor, but still noticeable. To make it easier to notice the difference, in my game I forced the sprite batch render method to repeatedly render itself 100 times per render call. Without the changes, in my benchmark scenario these were taking an avg of 136 microseconds, while with the change, that time decreased to 100 microseconds.
Checklist
docs
and added dartdoc comments with///
.examples
ordocs
.Breaking Change?
Related Issues
Replace or remove this text.