using lut for performance improvement - #14263
Conversation
| // bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 | ||
| // Then the below line "std::memcpy(&vec[i * 8], expanded.data(), 8);" | ||
| // grabs 8 values at once from the LUT instead of calculating each bit one by one | ||
| static const std::array<std::array<uint8_t, 8>, 256> bit_expand_lut = []() { |
There was a problem hiding this comment.
Check if can be done constexpr to calculate at compile time
There was a problem hiding this comment.
Done - had to use template and std::integer_sequence to make it compile with C++14 standard.
Time measuring results:
The look takes about 400 microseconds without improvement, and it takes about 10 microseconds with it.
Maybe we should make it remain as it was before the compile time thing to make it easier to read.
What do you think @OhadMeir ?
There was a problem hiding this comment.
Very nice time improvement, good catch!
OK, both using compile time and initialization time have their own benefits. If you prefer the readability of the previous version then revert this change.
88b3ad8 to
5ebb1d2
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR improves performance for bit expansion operations in rendering code by implementing a pre-computed lookup table (LUT) to replace bit-by-bit calculations. The optimization changes how occupancy grid data bits are expanded from packed bytes to individual pixel values.
- Introduces a static lookup table that pre-computes all 256 possible byte-to-8-pixel expansions
- Replaces the inner loop bit extraction with a single memcpy operation using the LUT
- Pre-allocates the output vector to avoid dynamic resizing during the loop
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Since no internal tracking can you write the motivation & performance result in the ticket description? |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.