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

CANParser: Update CAN data handling functions to accept raw data and size parameters #1040

Closed
wants to merge 1 commit into from

Conversation

deanlee
Copy link
Contributor

@deanlee deanlee commented May 7, 2024

When parsing CAN messages, CanParser creates a memory copy for each message solely to satisfy the checksum calculation function's requirement, which expects a std::vector<uint8_t> as parameter. This approach is inefficient and slows down the parsing process.

std::vector<uint8_t> data(dat.size(), 0);
memcpy(data.data(), dat.begin(), dat.size());

This PR updates all functions responsible for handling CAN data to accept raw data pointers uint8_t* data and size parameters size_t size instead of using std::vector<uint8_t>. This adjustment aims to enhance performance and reduce memory overhead by avoiding unnecessary memory allocations and copies associated with vector usage.

@deanlee deanlee marked this pull request as draft June 8, 2024 02:19
std::vector<uint8_t> data(dat.size(), 0);
memcpy(data.data(), dat.begin(), dat.size());
state_it->second.parse(nanos, data);
state_it->second.parse(nanos, dat.begin(), dat.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just pass the capnp::Data::Reader, or do we want to remove capnp as a dependency too?

@sshane
Copy link
Contributor

sshane commented Jun 8, 2024

How much does this improve performance? I don't see much of a difference on a comma 3X

@deanlee
Copy link
Contributor Author

deanlee commented Jun 8, 2024

This change won't significantly impact the performance of the master branch, as the master spends lots of time on Cython code. However, it will enhance the performance of the C++ code, particularly after #1046. Currently, there are two performance bottlenecks in the C++ code that can be addressed: memory-aligned copying and the use of vectors. This adjustment is expected to boost the performance of the C++ code, with even greater improvements expected on devices.

@deanlee deanlee closed this Jul 31, 2024
@deanlee deanlee deleted the pass_bytes branch July 31, 2024 17:58
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.

None yet

2 participants