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

Optimise performance of Canvas widget on Android #3070

Open
philouche opened this issue Jan 4, 2025 · 1 comment
Open

Optimise performance of Canvas widget on Android #3070

philouche opened this issue Jan 4, 2025 · 1 comment
Labels
android The issue relates to Android mobile support. awaiting details More details are needed before the issue can be triaged. enhancement New features, or improvements to existing features.

Comments

@philouche
Copy link

Describe the bug

Hello toga team,
I have an app with a canvas and I draw a little circle every time the user press the canvas.
But after a large number of circles, let say 100 or 200 circles, the app begins to lag and the new circles appear after a delay and the log say that some frames have been skipped.
I made the same kind of app with android studio and there is no slow down.
Do you have an idea of the problem ?
Than you.

Steps to reproduce

Make a canvas.
Draw a circle at each on press event
Lags appear after many circles

Expected behavior

No slow down on redraw

Screenshots

No response

Environment

  • Operating System: android
  • Python version: 3.12
  • Software versions:
    • Briefcase:
    • Toga: 0.4.8
    • ...

Logs


Additional context

No response

@philouche philouche added the bug A crash or error in behavior. label Jan 4, 2025
@freakboy3742 freakboy3742 changed the title Canvas becomes slower and slower Optimise performance of Canvas widget Jan 5, 2025
@freakboy3742 freakboy3742 added enhancement New features, or improvements to existing features. awaiting details More details are needed before the issue can be triaged. and removed bug A crash or error in behavior. labels Jan 5, 2025
@freakboy3742 freakboy3742 changed the title Optimise performance of Canvas widget Optimise performance of Canvas widget on Android Jan 5, 2025
@freakboy3742 freakboy3742 added the android The issue relates to Android mobile support. label Jan 5, 2025
@freakboy3742
Copy link
Member

If the speed decreases roughly linearly with each new circle being added, then it's likely "operating as normal".

A direct comparison with a native Android implementation isn't really possible. If you're writing a native implementation, you're writing directly against the native APIs. You can write code that draws 200 circles, and all it needs to do is draw 200 circles. Any redraw instructions can be optimised directly into the Android redraw process.

However, a Python-based implementation needs to carry the overhead of the Python interpreter itself, and then adds on the overhead of converting objects from Python to Java. Each additional layer adds overhead; and also loses opportunities to optimised based on integration with native redraw processes.

I'm going to recategorize this as an enhancement, rather than a bug; there's nothing inherently wrong with the current implementation - you're just hitting the performance limit. Could the Canvas widget be faster? Possibly. How would that be achieved? It's not at all clear. A lot more investigation is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android The issue relates to Android mobile support. awaiting details More details are needed before the issue can be triaged. enhancement New features, or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

2 participants