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

[bytebuffer] Rework ByteBuffer using templates #7638

Merged
merged 13 commits into from
Oct 28, 2024

Conversation

clydebarrow
Copy link
Contributor

@clydebarrow clydebarrow commented Oct 20, 2024

What does this implement/fix?

With requests for additional functionality in the ByteBuffer class I've reworked it using templates and all in-lineable functions. This will:

  1. Reduce the code size impact when ByteBuffer is not used to zero;
  2. Reduce the code size impact to only those functions that are used in any given build;
  3. Improve speed with inlining.
  4. Allow new features to be more easily added.

The additional functionality requested (see #7625) was to allow puts and gets into the buffer without changing the current position. This is achieved with functions as below. In addition templated functions are added for all data types.

// Examples
void put_uint8(uint8_t value, size_t offset);
double get_double(size_t offset);

// Templated versions

T get<T>();
T get<T>(size_t offset);
void put<T>(T value);
void put<T>(T value, size_t offset);

Where T can be any of the supported types (8, 16, 32 bit integers, signed or unsigned, float or double.)

Now a component

The code has been moved from core into its own component. This will require any component using it to auto-load bytebuffer. The rationale for this change is to eliminate any possible code footprint when ByteBuffer is not used, and to facilitate CI testing.

Tests

Ideally this would be tested during CI with unit tests. This is currently not possible within the existing CI framework.
The test code only gets built during CI but it has been runtime tested on host and ESP32 platforms.

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
  • host

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:

@clydebarrow clydebarrow requested a review from a team as a code owner October 20, 2024 06:10
@clydebarrow clydebarrow mentioned this pull request Oct 20, 2024
13 tasks
@codecov-commenter
Copy link

codecov-commenter commented Oct 20, 2024

Codecov Report

Attention: Patch coverage is 32.25806% with 42 lines in your changes missing coverage. Please review.

Project coverage is 53.98%. Comparing base (4d8b5ed) to head (de08adc).
Report is 1525 commits behind head on dev.

Files with missing lines Patch % Lines
esphome/dashboard/web_server.py 11.42% 31 Missing ⚠️
esphome/writer.py 14.28% 6 Missing ⚠️
esphome/dashboard/core.py 72.22% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #7638      +/-   ##
==========================================
+ Coverage   53.70%   53.98%   +0.27%     
==========================================
  Files          50       50              
  Lines        9408     9764     +356     
  Branches     1654     1344     -310     
==========================================
+ Hits         5053     5271     +218     
- Misses       4056     4167     +111     
- Partials      299      326      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@clydebarrow clydebarrow added this to the 2024.11.0b1 milestone Oct 22, 2024
@probot-esphome
Copy link

Hey there @clydebarrow,
Thanks for submitting this pull request! Can you add yourself as a codeowner for this integration? This way we can notify you if a bug report for this integration is reported.
In __init__.py of the integration, please add:

CODEOWNERS = ["@clydebarrow"]

And run script/build_codeowners.py

(message by NeedsCodeownersLabel)

@clydebarrow clydebarrow changed the title [core] Rework ByteBuffer using templates [bytebuffer] Rework ByteBuffer using templates Oct 27, 2024
@jesserockz jesserockz merged commit 858d97c into esphome:dev Oct 28, 2024
27 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2024
@clydebarrow clydebarrow deleted the bytebuffer branch November 5, 2024 20:47
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.

3 participants