diff options
author | Ali K. Zadeh <alikz@google.com> | 2022-05-09 17:47:32 +0000 |
---|---|---|
committer | Ali K. Zadeh <alikz@google.com> | 2022-05-09 18:16:52 +0000 |
commit | b5d577689ee48a52fb8f2e5623948821950143f6 (patch) | |
tree | 26a989181b92e9f3804d75b7278f86af5daf6609 | |
parent | 2f3e92445745ed6e9914bf5efdf16892dd7df150 (diff) | |
download | camera-b5d577689ee48a52fb8f2e5623948821950143f6.tar.gz |
Made changes to GoogSensorMotion::QuerySensorEventsBetweenTimestamps function to have less calls to std::vector::push_back_slow_path
The function now pre-allocates the vectors event_timestamps,
motion_vector_x, motion_vector_y, motion_vector_z,
event_arrival_timestamps (with making calls to vector::reserve), in
order to avoid multiple calls to push_back_slow_path.
Bug: 231138713
Test: Profiling test done, and the function is no longer showing up
here: https://pprof.corp.google.com/?id=e0980f27db83f9cb0cba5b8ae5d3b73b&tab=flame&pivot=push_back_slow_path
Change-Id: I481771aa1db0fb4d145e91a305582a30d48e8e48
-rw-r--r-- | common/sensor_listener/goog_sensor_motion.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/common/sensor_listener/goog_sensor_motion.cc b/common/sensor_listener/goog_sensor_motion.cc index f312ced..b12ea8e 100644 --- a/common/sensor_listener/goog_sensor_motion.cc +++ b/common/sensor_listener/goog_sensor_motion.cc @@ -147,6 +147,13 @@ void GoogSensorMotion::QuerySensorEventsBetweenTimestamps( event_arrival_timestamps->clear(); std::lock_guard<std::mutex> l(event_buffer_lock_); + + event_timestamps->reserve(event_buffer_.size()); + motion_vector_x->reserve(event_buffer_.size()); + motion_vector_y->reserve(event_buffer_.size()); + motion_vector_z->reserve(event_buffer_.size()); + event_arrival_timestamps->reserve(event_buffer_.size()); + for (const auto& event : event_buffer_) { int64_t event_time = event.sensor_event.timestamp; if (event_time <= start_time || event_time > end_time) { |