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

Use iterators in interface send methods #106

Merged
merged 3 commits into from
Feb 9, 2020
Merged

Use iterators in interface send methods #106

merged 3 commits into from
Feb 9, 2020

Conversation

jamwaffles
Copy link
Collaborator

@jamwaffles jamwaffles commented Feb 8, 2020

Hi! Thank you for helping out with SSD1306 development! Please:

  • Check that you've added documentation to any new methods
  • Rebase from master if you're not already up to date
  • Add or modify an example if there are changes to the public API
  • Add a CHANGELOG.md entry in the Unreleased section under the appropriate heading (Added, Fixed, Changed, etc)
  • Run rustfmt on the project with cargo fmt --all - CI will not pass without this step
  • Check that your branch is up to date with master and that CI is passing once the PR is opened

PR description

Switches some for loops for iterators to speed up sends (and hopefully reduce code size) by eliding bounds checks.

@jamwaffles jamwaffles force-pushed the optimise-iter branch 2 times, most recently from dcb2c60 to 627efd8 Compare February 8, 2020 16:46
* Dedupes byte/bit index calculation
* Replaces a slice index operation with `get_mut`, eliding bounds
checks (I think - the call tree is pretty hairy)
* Replaces if/else bit set/clear op with bit ops. See here for asm
output: https://godbolt.org/z/YRSanf
@jamwaffles
Copy link
Collaborator Author

I just added some optimisations in 6ff90ff which should make set_pixel calls a lot faster. Unsure how to bench, but for one thing the change from an if/else to bit manip ops to set the pixel value in a byte should be much faster now. The generated assembly says so.

Copy link
Collaborator

@therealprof therealprof left a comment

Choose a reason for hiding this comment

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

Funny, on my MCUmeter (ARMv6-m) I'm actually seeing a slight pessimation in binary size:

-0.1%   6.2%   496B  embedded_graphics embedded_graphics::fonts::text::<impl embedded_graphics::drawable::Drawable<C> for &embedded_graphics::style::styled::Styled<embedded_graphics::fonts::text::Text,embed...
+0.1%   5.0%   400B  embedded_graphics embedded_graphics::fonts::text::<impl embedded_graphics::drawable::Drawable<C> for &embedded_graphics::style::styled::Styled<embedded_graphics::fonts::text::Text,embed...
+0.0%   3.7%   296B            ssd1306 ssd1306::properties::DisplayProperties<DI>::bounded_draw
-0.0%   2.6%   210B            ssd1306 ssd1306::properties::DisplayProperties<DI>::bounded_draw

but there's a new player on the field:

+0.0%   0.7%    52B          [Unknown] __aeabi_lmul

Anyway, looks nice on paper, is slight optimisation and offers ground for more optimisation so let's ship it.

@jamwaffles
Copy link
Collaborator Author

Yeah, slightly bigger but maybe faster so worth it in the end? I dunno tbh, it's all tradeoffs lol. Thanks for the review!

@jamwaffles jamwaffles merged commit cecc6dc into master Feb 9, 2020
@jamwaffles jamwaffles deleted the optimise-iter branch February 9, 2020 12:39
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