Skip to content

⚡ [Performance] Avoid object allocation in TouchButtonView.onDraw#10

Closed
SirDank wants to merge 1 commit into
mainfrom
performance-avoid-allocation-ondraw-12663536340180543958
Closed

⚡ [Performance] Avoid object allocation in TouchButtonView.onDraw#10
SirDank wants to merge 1 commit into
mainfrom
performance-avoid-allocation-ondraw-12663536340180543958

Conversation

@SirDank

@SirDank SirDank commented May 26, 2026

Copy link
Copy Markdown
Collaborator

💡 What: Moved RectF allocation in TouchButtonView.onDraw to a class member and updated it with .set() instead of creating a new object every frame.
🎯 Why: Object allocations in onDraw are a well-known Android performance anti-pattern. Since onDraw can be called 60 times a second during animations, allocating objects inside it triggers garbage collection more frequently, leading to frame drops. Moving the allocation to initialization and mutating the object directly resolves this overhead.
📊 Measured Improvement: I was unable to show a meaningful performance improvement because the Gradle build fails from missing heavy assets (lwjgl) that cannot be easily built in the sandbox environment, making it impractical to run a full device-based or Robolectric-based benchmark test. However, this is a standard and universally accepted performance optimization for Android Views.


PR created automatically by Jules for task 12663536340180543958 started by @SirDank

Moved `RectF` allocation in `TouchButtonView.onDraw` to a class member and updated it with `.set()` instead of creating a new object every frame. This avoids garbage collection overhead during animations.

Co-authored-by: SirDank <52797753+SirDank@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@beebono

beebono commented May 26, 2026

Copy link
Copy Markdown
Contributor

Merged in perf category PR commit d6138f9, authors preserved.

@beebono beebono closed this May 26, 2026
@beebono beebono deleted the performance-avoid-allocation-ondraw-12663536340180543958 branch May 26, 2026 12: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.

2 participants