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

perf: optimize serialization of arrays of trivial D-Bus types #340

Merged
merged 2 commits into from
Jul 27, 2023

Conversation

pliniofpa
Copy link
Contributor

@pliniofpa pliniofpa commented Jul 26, 2023

Discussion #338 and Issue #339

Closes #338
Fixes #339

@sangelovic
Copy link
Collaborator

sangelovic commented Jul 27, 2023

Hey @pliniofpa, this is surely an improvement and we will take this in. I've looked at your changes and have done adjustments on your branch. I simplified it. In essence, template specializations have been removed, instead constexpr if is used in vector functions where either fast path or slow path is taken depending on _Element traits. signature_of type trait class has been extended with is_trivial_dbus_type for that purpose. appendArray() and readArray() are now private and work with pointers directly. Clients simply serialize/deserialize vectors and the rest is hidden.

Additionally, I made all the insertion and extraction operators as member functions. Until now, some were member functions and some were free functions, I don't know why. Now 1. it's consistent, 2. all supported overloads are easily visible together in Message class definition, 3. it allows to make underlying appendArray() and readArray() functions as private, which they shall be. So a number of changes is due to that additional, not-that-much-related refactoring.

Feel free to review. Does it look OK to you? If so, let me know and we'll merge it.

Thank you for sharing your observation and submitting this PR!

@pliniofpa
Copy link
Contributor Author

pliniofpa commented Jul 27, 2023 via email

Copy link
Contributor Author

@pliniofpa pliniofpa left a comment

Choose a reason for hiding this comment

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

This looks good to me.
Thanks.

@sangelovic
Copy link
Collaborator

sangelovic commented Jul 27, 2023

@pliniofpa

Off topic:
Is there a reason why sdbus-cpp doesn't have members to/from std::array<>?

No reason. We can add it. There is actually a discussion going on with that proposal, among others, at #328.

The open question is what the behavior should be when the std::array size is lower or greater than the real number of elements when deserializing from the message. Will that be not allowed (an exception thrown)? Shall we populate only as many elements as std::array enables and throw away the rest? Shall we fill the array up until the number of elements in the message and leave the rest of elements in the array untouched?

Feel free to contribute, either in the discussion at #328 or by submitting a PR ;)

Thanks and take care.

@sangelovic sangelovic changed the title Improve performance of std::vector<> per Issue #339. perf: optimize serialization of arrays of trivial D-Bus types Jul 27, 2023
@sangelovic sangelovic merged commit 29c877a into Kistler-Group:master Jul 27, 2023
@pliniofpa
Copy link
Contributor Author

pliniofpa commented Jul 27, 2023 via email

@sangelovic
Copy link
Collaborator

@pliniofpa Hi Plinio, yes I agree with you, thanks, I've just replied in that thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Huge performance improvement when using sd_bus_message_*_array() instead of sd_bus_message_*_basic()
2 participants