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

Use custom ember-buffer decode on codegen data model Read as well. #36229

Merged
merged 4 commits into from
Oct 24, 2024

Conversation

andy31415
Copy link
Contributor

This saves about 1KB of flash compared to the alternative (more template-heavy) approach.

image

Copy link

Review changes with SemanticDiff.

Copy link

github-actions bot commented Oct 24, 2024

PR #36229: Size comparison from 515bc3b to 91d5458

Full report (68 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section 515bc3b 91d54583 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1350106 1350120 14 0.0
RAM 104120 104120 0 0.0
bl702 lighting-app bl702+eth FLASH 647856 647856 0 0.0
RAM 25233 25233 0 0.0
bl702+wifi FLASH 825164 825164 0 0.0
RAM 13965 13965 0 0.0
bl706+mfd+rpc+littlefs FLASH 1054154 1054154 0 0.0
RAM 23821 23821 0 0.0
bl702l lighting-app bl702l+mfd+littlefs FLASH 974938 974938 0 0.0
RAM 16468 16468 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 836676 836660 -16 -0.0
RAM 123676 123676 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 821960 821960 0 0.0
RAM 125556 125556 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 768540 768532 -8 -0.0
RAM 114048 114048 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 752792 752792 0 0.0
RAM 114240 114240 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 627474 627466 -8 -0.0
RAM 206132 206132 0 0.0
lock CC3235SF_LAUNCHXL FLASH 667458 667458 0 0.0
RAM 206284 206284 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 678629 678621 -8 -0.0
RAM 78692 78692 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 698481 698465 -16 -0.0
RAM 81324 81324 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 698481 698465 -16 -0.0
RAM 81324 81324 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 655409 655401 -8 -0.0
RAM 73760 73760 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 615053 615037 -16 -0.0
RAM 71644 71644 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 634681 634665 -16 -0.0
RAM 74196 74196 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 634681 634665 -16 -0.0
RAM 74196 74196 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 634309 634309 0 0.0
RAM 74692 74692 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 654025 654017 -8 -0.0
RAM 77244 77244 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 654025 654017 -8 -0.0
RAM 77244 77244 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 609685 609677 -8 -0.0
RAM 68780 68780 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 629545 629529 -16 -0.0
RAM 71412 71412 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 629545 629529 -16 -0.0
RAM 71412 71412 0 0.0
efr32 lock-app BRD4187C FLASH 925644 925644 0 0.0
RAM 159920 159920 0 0.0
BRD4338a FLASH 742232 742232 0 0.0
RAM 232580 232580 0 0.0
window-app BRD4187C FLASH 1018568 1018568 0 0.0
RAM 128264 128264 0 0.0
esp32 all-clusters-app c3devkit DRAM 95256 95256 0 0.0
FLASH 1540020 1540020 0 0.0
IRAM 82538 82538 0 0.0
m5stack DRAM 116192 116192 0 0.0
FLASH 1550198 1550198 0 0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4688 4688 0 0.0
FLASH 2756403 2743505 -12898 -0.5
RAM 129520 129520 0 0.0
all-clusters-app debug unknown 5528 5528 0 0.0
FLASH 6070438 6058950 -11488 -0.2
RAM 523840 523840 0 0.0
all-clusters-minimal-app debug unknown 5424 5424 0 0.0
FLASH 5399618 5387534 -12084 -0.2
RAM 242416 242416 0 0.0
bridge-app debug unknown 5408 5408 0 0.0
FLASH 4724310 4711446 -12864 -0.3
RAM 218384 218384 0 0.0
chip-tool debug unknown 5960 5960 0 0.0
FLASH 13076952 13060514 -16438 -0.1
RAM 584402 584402 0 0.0
chip-tool-ipv6only arm64 unknown 21408 21408 0 0.0
FLASH 11183176 11170504 -12672 -0.1
RAM 635344 635344 0 0.0
fabric-admin debug unknown 5792 5792 0 0.0
FLASH 11331481 11315043 -16438 -0.1
RAM 584890 584890 0 0.0
fabric-bridge-app debug unknown 4632 4632 0 0.0
FLASH 4550604 4537294 -13310 -0.3
RAM 205336 205336 0 0.0
fabric-sync debug unknown 4816 4816 0 0.0
FLASH 5264517 5250693 -13824 -0.3
RAM 465416 465416 0 0.0
lighting-app debug+rpc+ui unknown 6056 6056 0 0.0
FLASH 5668625 5655505 -13120 -0.2
RAM 228488 228488 0 0.0
lock-app debug unknown 5344 5344 0 0.0
FLASH 4773966 4760874 -13092 -0.3
RAM 204472 204472 0 0.0
ota-provider-app debug unknown 4720 4720 0 0.0
FLASH 4401624 4387584 -14040 -0.3
RAM 198192 198192 0 0.0
ota-requestor-app debug unknown 4656 4656 0 0.0
FLASH 4541230 4527392 -13838 -0.3
RAM 202760 202760 0 0.0
shell debug unknown 4216 4216 0 0.0
FLASH 3095165 3082445 -12720 -0.4
RAM 160368 160368 0 0.0
thermostat-no-ble arm64 unknown 9448 9448 0 0.0
FLASH 4140784 4130720 -10064 -0.2
RAM 242896 242896 0 0.0
tv-app debug unknown 5624 5624 0 0.0
FLASH 6007573 5994325 -13248 -0.2
RAM 596256 596256 0 0.0
tv-casting-app debug unknown 5208 5208 0 0.0
FLASH 11281821 11268365 -13456 -0.1
RAM 694536 694536 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 915564 915564 0 0.0
RAM 143357 143357 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 886032 886032 0 0.0
RAM 141496 141496 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 848972 848972 0 0.0
RAM 142265 142265 0 0.0
nxp contact k32w0+release FLASH 582424 582424 0 0.0
RAM 71092 71092 0 0.0
mcxw71+release FLASH 596904 596904 0 0.0
RAM 63184 63184 0 0.0
light k32w0+release FLASH 619044 619044 0 0.0
RAM 70556 70556 0 0.0
k32w1+release FLASH 683144 683144 0 0.0
RAM 48816 48816 0 0.0
lock mcxw71+release FLASH 746712 746712 0 0.0
RAM 67340 67340 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1647652 1647668 16 0.0
RAM 212408 212408 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1553724 1553740 16 0.0
RAM 209208 209208 0 0.0
light cy8ckit_062s2_43012 FLASH 1468004 1468004 0 0.0
RAM 201200 201200 0 0.0
lock cy8ckit_062s2_43012 FLASH 1464964 1464964 0 0.0
RAM 225560 225560 0 0.0
qpg lighting-app qpg6105+debug FLASH 660552 660536 -16 -0.0
RAM 105420 105420 0 0.0
lock-app qpg6105+debug FLASH 618636 618628 -8 -0.0
RAM 99880 99880 0 0.0
stm32 light STM32WB5MM-DK FLASH 481928 481920 -8 -0.0
RAM 144844 144844 0 0.0
telink bridge-app tlsr9258a FLASH 681136 681136 0 0.0
RAM 91304 91304 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 620786 620786 0 0.0
RAM 50600 50600 0 0.0
light-switch-app-ota-shell-factory-data tlsr9528a FLASH 708768 708766 -2 -0.0
RAM 73940 73940 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 625738 625736 -2 -0.0
RAM 144468 144468 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 811748 811746 -2 -0.0
RAM 99100 99100 0 0.0
tizen all-clusters-app arm unknown 4912 4912 0 0.0
FLASH 1729988 1729952 -36 -0.0
RAM 90108 90108 0 0.0
chip-tool-ubsan arm unknown 10792 10792 0 0.0
FLASH 18237694 18237430 -264 -0.0
RAM 7945372 7945192 -180 -0.0

@tcarmelveilleux tcarmelveilleux changed the title Use cusom ember-buffer decode on codegen data model Read as well. Use custom ember-buffer decode on codegen data model Read as well. Oct 24, 2024
@mergify mergify bot merged commit 692983e into project-chip:master Oct 24, 2024
67 checks passed
Comment on lines +387 to +394
bool isSigned = (mAttributeType == ZCL_INT8S_ATTRIBUTE_TYPE) //
|| (mAttributeType == ZCL_INT16S_ATTRIBUTE_TYPE) //
|| (mAttributeType == ZCL_INT24S_ATTRIBUTE_TYPE) //
|| (mAttributeType == ZCL_INT32S_ATTRIBUTE_TYPE) //
|| (mAttributeType == ZCL_INT40S_ATTRIBUTE_TYPE) //
|| (mAttributeType == ZCL_INT48S_ATTRIBUTE_TYPE) //
|| (mAttributeType == ZCL_INT56S_ATTRIBUTE_TYPE) //
|| (mAttributeType == ZCL_INT64S_ATTRIBUTE_TYPE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we are reinventing chip::app::IsSignedAttributeType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably me not knowing all the functions we have ... will update it.


if (mIsNullable && (value.uint_value == nullValue))
{
// MaxValue is used for NULL setting
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment does not make sense for signed types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will re-write it. It does rely that we have a union and we store the null value as a uint64_t ... so we are looking at a static u64 cast on both sides here ...

Comment on lines +456 to +457
case ZCL_INT8U_ATTRIBUTE_TYPE: // Unsigned 8-bit integer
return writer.Put(tag, static_cast<uint8_t>(value.uint_value));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we doing this? Assuming the value is in range at all, we can just Put() as a 64-bit signed/unsigned respectively depending on isSigned and don't need this whole big switch and the casting.

Comment on lines +499 to +500
case 0xFF:
return writer.PutNull(tag);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will incorrectly encode null even if !mIsNullable, instead of correctly erroring out.

}
if (NumericAttributeTraits<float>::IsNullValue(value.value))
{
return writer.PutNull(tag);
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, this needs to check mIsNullable!

}
if (NumericAttributeTraits<double>::IsNullValue(value.value))
{
return writer.PutNull(tag);
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to check mIsNullable.

@@ -73,6 +85,10 @@ class EmberAttributeDataBuffer
/// Takes into account internal mIsNullable.
CHIP_ERROR DecodeSignedInteger(chip::TLV::TLVReader & reader, EndianWriter & writer);

/// Encodes the UNSIGNED integer into `writer`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The code is not just for unsigned. What is this comment talking about?

yyzhong-g pushed a commit to yyzhong-g/connectedhomeip that referenced this pull request Dec 12, 2024
…roject-chip#36229)

* Use EmberAttributeDataBuffer for codegen provider _Read

* Fix comments

* Restyled by clang-format

---------

Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants