blazoncek / WLED

Control WS2812B and many more types of digital RGB LEDs with an ESP8266 or ESP32 over WiFi!
MIT License
31 stars 0 forks source link

general improvement: use _fast_ int types when speed matters #32

Closed softhack007 closed 2 years ago

softhack007 commented 2 years ago

As a general improvement when speed matters, use _fast_ versions of fixed width integers. Operations on these types are usually faster than using the "exact" types like uint8_t etc. For example, when doing an operation on uint8_t, the compiler may need additional instructions for loading/storing from unaligned (odd) addresses, and extra operations to ensure that computation results remain in 8bit - like & 0xFFafter each addition.

The fast types are:

These are the "fastest signed/unsigned integer type with width of at least 8, 16, and 32 bits respectively".

https://en.cppreference.com/w/c/types/integer

https://stackoverflow.com/questions/10338966/the-use-of-int8-t-on-some-small-values-on-32bit-machine-is-useless-optimization

blazoncek commented 2 years ago

Thank you for the insight!

As I am readying 2D (and audioreactive as a usermod) it may be a good time to revisit the use of uint8_t and uint16_t througout WLED.

blazoncek commented 2 years ago

Most of the uint8_t and uint16_t uses in FX.cpp were replace by int or size_t which use CPU native size and should be optimised. Other cases are not executed too often and can be dealt with at a later time if at all.