-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[codegen/CodegenDataModelProvider.cpp]: Move the constructor of AttributeEntry inside a closer "for" loop. #38866
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
[codegen/CodegenDataModelProvider.cpp]: Move the constructor of AttributeEntry inside a closer "for" loop. #38866
Conversation
PR #38866: Size comparison from 8167c5f to 7ba17d8 Full report (75 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
PR #38866: Size comparison from 8167c5f to 72106ce Increases above 0.2%:
Full report (73 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
…y_inside_for_loop
PR #38866: Size comparison from dfa46da to 056b400 Full report (73 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
…y_inside_for_loop
PR #38866: Size comparison from 70e5039 to 041021b Full report (73 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this perhaps let us make the attributeId member of AttributeEntry const?
…y_inside_for_loop
PR #38866: Size comparison from f4d171a to 96c02e9 Full report (73 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
Unfortunately not yet. On the file
The third line is a direct assign operation, which cannot happen when a class has a const member variable. Because the class cannot be assigned using the default assignment operator due to the const member, the compiler does not generate one. We could define our own custom assignment operator for the class |
…y_inside_for_loop
PR #38866: Size comparison from fdacd16 to c1137c0 Full report (73 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
So can we do: DataModel::AttributeFinder finder(mDataModelProvider);
std::optional<DataModel::AttributeEntry> attributeEntry = finder.Find(aPath); To use a constructor? |
Yes, we should be able to do this, using the (default) copy constructor. We probably will need to test in detail that any "shallow" copy doesn't break the unit tests, but this looks doable, yes. I will create a follow up issue addressing this. |
…buteEntry inside a closer "for" loop. (project-chip#38866) * Moved AttributeEntry constructor inside of "for" loop. * Using move semantics to handle object "globalListEntry". Renaming "attribute".
Fixes #38769
Inside https://github.com/project-chip/connectedhomeip/blob/master/src/data-model-providers/codegen/CodegenDataModelProvider.cpp, at the function
Attributes()
, we have the declaration of the variableglobalListEntry
of typeDataModel::AttributeEntry
. This declaration calls theAttributeEntry
constructor, with the first parameter (attributeId
) set to zero by default. This value is set later inside afor
loop, immediately after theglobalListEntry
declaration.We have moved the
AttributeEntry
constructor call inside this nearfor
loop, since in here we already know the value of the first parameter, and we can avoid calling the constructor with unnecessary filler or garbage data.The codesize does not increase, and in fact it does decrease around ~1 KByte.
We got rid of the now redundant line:
globalListEntry.attributeId = attribute;
inside the
for
loop.Also, the use of
std::move()
enables move semantics, which allows efficient transfer of resources (in this case, theDataModel::AttributeEntry
instance) from one object to another, avoiding unnecessary copies.Function to change
CodegenDataModelProvider::Attributes()
Testing
CI checks will be run against this PR.