Skip to content

using lut for performance improvement - #14263

Merged
remibettan merged 2 commits into
realsenseai:developmentfrom
remibettan:improving_occupancy_rendering_performance
Sep 9, 2025
Merged

using lut for performance improvement#14263
remibettan merged 2 commits into
realsenseai:developmentfrom
remibettan:improving_occupancy_rendering_performance

Conversation

@remibettan

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread common/rendering.h
// 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 = []() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Check if can be done constexpr to calculate at compile time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will, thanks

@remibettan
remibettan force-pushed the improving_occupancy_rendering_performance branch from 88b3ad8 to 5ebb1d2 Compare September 3, 2025 07:10
@remibettan
remibettan requested a review from OhadMeir September 3, 2025 07:10
@Nir-Az
Nir-Az requested a review from Copilot September 3, 2025 07:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread common/rendering.h Outdated
@Nir-Az

Nir-Az commented Sep 3, 2025

Copy link
Copy Markdown
Collaborator

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>
@remibettan
remibettan merged commit 62fcd91 into realsenseai:development Sep 9, 2025
25 of 26 checks passed
@remibettan
remibettan deleted the improving_occupancy_rendering_performance branch July 8, 2026 12:05
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.

4 participants