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

Speed up writing protobuf strings/bytes #5828

Merged
merged 1 commit into from
Dec 19, 2023
Merged

Speed up writing protobuf strings/bytes #5828

merged 1 commit into from
Dec 19, 2023

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Nov 24, 2023

What does this implement/fix?

Speed up writing protobuf strings/bytes

I recently got an esp32 cam and noticed the performance was not so great over the api (https://community.home-assistant.io/t/getting-better-performance-from-an-espcam32/561615)

I tried a few different ways ... and this might be faster but not sure if its safe

    this->buffer_->resize(old_size + len);
    std::memcpy(&(*this->buffer_)[old_size], data, len);

so I settled on

this->buffer_->insert(this->buffer_->end(), data, data + len);

after reading https://stackoverflow.com/questions/2208293/what-is-the-most-efficient-way-to-append-one-stdvector-to-the-end-of-another , in theory it should be 2x the speed of the push_back but I currently have no way to validate that its actually faster on the ESP and not just locally.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

Copy link
Member

@jesserockz jesserockz left a comment

Choose a reason for hiding this comment

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

Seems like a very sensible change

@bdraco bdraco marked this pull request as ready for review December 19, 2023 04:31
@probot-esphome
Copy link

Hey there @OttoWinter, mind taking a look at this pull request as it has been labeled with an integration (api) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@jesserockz jesserockz added this to the 2023.12.0b4 milestone Dec 19, 2023
@jesserockz jesserockz merged commit cd06dc7 into dev Dec 19, 2023
47 checks passed
@jesserockz jesserockz deleted the proto_writes branch December 19, 2023 05:24
@bdraco
Copy link
Member Author

bdraco commented Dec 19, 2023

thanks

@jesserockz jesserockz mentioned this pull request Dec 20, 2023
@jesserockz jesserockz mentioned this pull request Dec 20, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants