Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Optimization in sprite batch #2861

Merged
merged 1 commit into from Nov 21, 2023
Merged

Conversation

erickzanardo
Copy link
Member

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 to drawAtlas 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

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Replace or remove this text.

@erickzanardo erickzanardo requested a review from a team November 21, 2023 17:31
@erickzanardo erickzanardo changed the title feat: micro optimization in sprite batch feat: M]icro optimization in sprite batch Nov 21, 2023
@erickzanardo erickzanardo changed the title feat: M]icro optimization in sprite batch feat: Micro optimization in sprite batch Nov 21, 2023
Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not a minor performance improvement with more than 20%, good job!

@erickzanardo erickzanardo changed the title feat: Micro optimization in sprite batch feat: Optimization in sprite batch Nov 21, 2023
@erickzanardo erickzanardo merged commit 208d789 into main Nov 21, 2023
11 checks passed
@erickzanardo erickzanardo deleted the feat/spritebatch-null-colors branch November 21, 2023 20:06
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.

None yet

2 participants