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

Optimisation pass #93

Merged
merged 17 commits into from
Aug 25, 2024
Merged

Optimisation pass #93

merged 17 commits into from
Aug 25, 2024

Conversation

ASleepyCat
Copy link
Collaborator

@ASleepyCat ASleepyCat commented Aug 17, 2024

Optimisation pass, primarily aimed at reducing the number of RGB update calls and reducing code size.
Mostly targets IIDX mode due to TT misfiring/misinputs from low polling rates, SDVX mode doesn't really have much going on except for the ADC stuff.

Benchmarks

Binary size

Using -O2. Compiled with avr-gcc 14.1.0 using pre-compiled builds from here. Sizes obtained by running avr-objdump -Pmem-usage beef.elf.

Section master optimisation-pass Change
Program 21690 20954 -3.4%
Data 1146 1003 -13.5%

Polling rate

Tested by using Gamepadla and having an incrementing counter on the X joystick axis, averaged over five tests. Using 6000 samples. LED refresh rate is set to 60Hz.

Lighting mode master optimisation-pass Change
HID (standby) 950.692 961.522 1.1%
HID (in-game) 959.552 998.004 4%
Off* 958.764 997.596 4%

*Off refers to the off lighting mode, not the "disable LED" toggle.

The fact that we see a 1% uplift in HID (standby) mode likely shows a real optimisation in our code, rather than it just coming from reducing the number of times we update the LEDs.

Changes

  • Only update RGBs when absolutely necessary
    • This fixes cases where the Disable RGB modes performs worse than disabling all LEDs
    • Should be an overall performance improvement, especially on more static RGB lighting animations
  • Change various ints to smaller sizes, especially around timing-related code
  • Remove parameters that pass in global variables
  • Remove some branching code
  • Reduce default BEEF_LED_REFRESH value from 240 to 60
    • A compiler warning is now produced when setting this to a higher value
  • Disable respective RGB update functions if RING_LIGHT_LEDS/LIGHT_BAR_LEDS are set to 0
    • Also whoops the LED counts weren't actually being used during compilation
  • Optimise and refactor Ticker, BreathingPattern classes to reduce code size and branching code

@ASleepyCat ASleepyCat changed the title Implement various optimisation Optimisation pass Aug 17, 2024
Base automatically changed from keyboard-mode to master August 20, 2024 07:37
@HWXLR8
Copy link
Owner

HWXLR8 commented Aug 20, 2024

Is this ready for review?

@ASleepyCat
Copy link
Collaborator Author

ASleepyCat commented Aug 21, 2024

Is this ready for review?

No, I still need to do some formal benchmarking and record the results here. Also need to do some playtesting.

@ASleepyCat
Copy link
Collaborator Author

Updated the description with my benchmark results, overall very good performance uplifts. Getting basically true 1000Hz polling without having to disable all LEDs.

@ASleepyCat ASleepyCat marked this pull request as ready for review August 24, 2024 01:22
@ASleepyCat ASleepyCat requested a review from HWXLR8 August 24, 2024 01:22
Copy link
Owner

@HWXLR8 HWXLR8 left a comment

Choose a reason for hiding this comment

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

Fantastic work. Tested and working on my phoenixwan (full speed w/ LEDs enabled), still awaiting test results from controllers with poorer sensor alignment, but will merge anyway since there is an objective increase in several metrics. Thanks for the PR!

@HWXLR8 HWXLR8 merged commit 480a28d into master Aug 25, 2024
2 checks passed
@HWXLR8 HWXLR8 deleted the optimisation-pass branch August 25, 2024 16:14
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