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

Android: Improve performance of sensor readings #90000

Conversation

melquiadess
Copy link
Contributor

Context

Once sensor listeners are registered, onSensorChanged() (and subsequently getRotatedValues()) get called multiple times per second. Obtaining WindowManager on each of those calls is superfluous and can be avoided by extracting it to a lazy class val. getRotatedValue() can also be called before checking sensor type, and used for each one of them, resulting in less code repetition.

@melquiadess melquiadess requested a review from a team as a code owner March 28, 2024 23:22
Copy link
Contributor

@m4gr3d m4gr3d left a comment

Choose a reason for hiding this comment

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

Looks good!

@YeldhamDev YeldhamDev added this to the 4.x milestone Mar 29, 2024
@akien-mga akien-mga changed the title Improve performance of sensor readings Android: Improve performance of sensor readings Apr 4, 2024
@akien-mga akien-mga modified the milestones: 4.x, 4.3 Apr 4, 2024
@akien-mga
Copy link
Member

Needs rebase after one of your recent merged PRs.

Once sensor listeners are registered, onSensorChanged() (and subsequently
getRotatedValues()) gets called multiple times per socond. Obtaining
WindowManager on each of those calls is superfluous and can be avoided
by extracting it to a lazy class val. getRotatedValue() can also be
called before checking sensor type, and used for each one of them,
resulting in less code repetition.
@melquiadess melquiadess force-pushed the improve-performance-of-sensor-readings branch from 589fc6b to f09d033 Compare April 4, 2024 13:19
@akien-mga akien-mga merged commit 1c571f9 into godotengine:master Apr 4, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@melquiadess melquiadess deleted the improve-performance-of-sensor-readings branch April 8, 2024 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants