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

Touch input causes big slowdown ( from get_keyboard_height ) - can use 12% to 30%+ of cpu before even passing to kivy #268

Closed
chozabu opened this issue Sep 13, 2014 · 8 comments

Comments

@chozabu
Copy link
Contributor

chozabu commented Sep 13, 2014

This is the function in question https://github.com/kivy/python-for-android/blob/master/recipes/android/src/android/_android.pyx#L174

profile of moving 1 finger for most of the time while profiling: http://chozabu.net/autopush/boardz-android-12-09-14-2135.profile ~12% total cpu usage by get_keyboard_height

profile of moving ~5 fingers for most of the time while profiling: http://chozabu.net/autopush/5fingers.profile ~30% total cpu usage by get_keyboard_height

It looks like eventes are issued by android when the keyboard changes - this would be a good time to cache the keyboard height:
ref - http://stackoverflow.com/a/18992807/445831

@chozabu
Copy link
Contributor Author

chozabu commented Sep 15, 2014

This bug is present on SGS3 - profiles in original post are from SGS3

may not be an issue on nexus4: http://chozabu.net/autopush/nexus4.profile

but on nexus4 app apparantly runs much slower anyway - though I did not see for myself.

also have not heard from tester if they were touching screen during nexus4 profile

Bug is present on motoG: http://chozabu.net/autopush/motog.profile
tester was touching screen with one finger some of the time

@chozabu
Copy link
Contributor Author

chozabu commented Sep 16, 2014

Update - the tester on the nexus4 said he was not touching the screen - perhaps for a second at the start. This means 12% usage on processing input when there is no input?

on motog test where one finger is being moved most of the time, dispach_input and on_motion combined are using over 20% of the CPU time!

@chozabu
Copy link
Contributor Author

chozabu commented Sep 16, 2014

motog1finger
dispatch input is the 15.62% block on right hand side
on__motion is the areas highlighted in bright green 9.78% in total - a small amount of that is included in the dispatch_input area though.

@chozabu
Copy link
Contributor Author

chozabu commented Sep 16, 2014

More profiles looking at touch input from simple pong app rather than my game boardz here: kivy/kivy#2470

as the app is much simpler, the profiles are somewhat clearer

@chozabu
Copy link
Contributor Author

chozabu commented Sep 18, 2014

Simply moving the lines:
from jnius import autoclass
python_act = autoclass('org.renpy.android.PythonActivity')
rctx = autoclass('android.graphics.Rect')()

into the global context did not prevent the issue, though it may have reduced it.

skipping the function get_keyboard_height corrects the issue, but is of course not a real solution.

@chozabu
Copy link
Contributor Author

chozabu commented Sep 23, 2014

relevant PR here: #272

@akshayaurora
Copy link
Member

Thanks to kived I just found out the real reason for the slowdown on touch input, onGlobalLayout Listener on the Java side was being called and triggered gettign keyboard height on every key, touch, movement.

Checking for height inside the layout listener and sending the key to kivy only when there is a height different solve the issue of keyboard_height being triggered again and again.

closed via 52e1861

@chozabu
Copy link
Contributor Author

chozabu commented May 8, 2015

Hooray! Nice one!

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

No branches or pull requests

2 participants