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

Redesign serialization classes #975

Merged
merged 14 commits into from Nov 23, 2019
Merged

Redesign serialization classes #975

merged 14 commits into from Nov 23, 2019

Conversation

Neverlord
Copy link
Member

  • Remove data_processor. This class unified serializer and
    deserializer interfaces to reduce code duplication. However, the
    implementation is quite complex and enforces virtual dispatch for all
    derived types.
  • Add write_inspector and read_inspector utility classes that inject
    an operator(). The previous recursive argument unrolling in the
    data_processor no longer has its place in C++17. The two new classes
    dispatch on apply member functions of their subtype via CRTP and use
    if constexpr to dispatch to the correct functions.
  • Refactor serializer and deserializer classes. These two classes
    still serve as base types for abstract inspectors, but no longer are
    connected through a common base.
  • Add binary_serializer and binary_deserializer classes. These two
    classes are the workhorses in CAF that run in performance-critical
    code. Hence, these implementations must reduce overhead as much as
    possible. Because of this, they do not inherit from the abstract
    interfaces and internally use the new error_code class over the
    generic error class.
  • Add handlers for binary_serializer and binary_deserializer to all
    CAF classes in addition to the generic versions.

Of course, the driving factor for these changes is performance. Here's the result of our micro benchmark for the binary serialization for current CAF master:

----------------------------------------------------------------------
Benchmark                            Time             CPU   Iterations
----------------------------------------------------------------------
Messages/BinarySerializer         1219 ns         1188 ns       580152
Messages/BinaryDeserializer       2478 ns         2410 ns       292372

And heere's the result for this branch:

----------------------------------------------------------------------
Benchmark                            Time             CPU   Iterations
----------------------------------------------------------------------
Messages/BinarySerializer          467 ns          455 ns      1549187
Messages/BinaryDeserializer       1852 ns         1805 ns       384634

That's a speedup of 2.6 for BinarySerializer and a speedup of 1.33 for BinaryDeserializer. Since especially the deserialization is the critical path, this should already make a notable difference. Our planned changes for message and the way we handle RTTI should speed things up even more.

This PR also removes some code related to message that I didn't bother to update to the new API. Simply because we're going to remove them anyway.

Neverlord and others added 11 commits November 18, 2019 09:33
- Remove `data_processor`. This class unified serializer and
  deserializer interfaces to reduce code duplication. However, the
  implementation is quite complex and enforces virtual dispatch for all
  derived types.
- Add `write_inspector` and `read_inspector` utility classes that inject
  an `operator()`. The previous recursive argument unrolling in the
  `data_processor` no longer has its place in C++17. The two new classes
  dispatch on `apply` member functions of their subtype via CRTP and use
  `if constexpr` to dispatch to the correct functions.
- Refactor `serializer` and `deserializer` classes. These two classes
  still serve as base types for abstract inspectors, but no longer are
  connected through a common base.
- Add `binary_serializer` and `binary_deserializer` classes. These two
  classes are the workhorses in CAF that run in performance-critical
  code. Hence, these implementations must reduce overhead as much as
  possible. Because of this, they do not inherit from the abstract
  interfaces and internally use the new `error_code` class over the
  generic `error` class.
- Add handlers for `binary_serializer` and `binary_deserializer` to all
  CAF classes in addition to the generic versions.
libcaf_core/caf/write_inspector.hpp Show resolved Hide resolved
libcaf_core/caf/callback.hpp Outdated Show resolved Hide resolved
libcaf_core/caf/deserializer.hpp Outdated Show resolved Hide resolved
libcaf_core/caf/detail/inspect.hpp Outdated Show resolved Hide resolved
libcaf_core/caf/detail/inspect.hpp Outdated Show resolved Hide resolved
libcaf_core/src/error_code.cpp Outdated Show resolved Hide resolved
libcaf_core/src/type_erased_tuple.cpp Outdated Show resolved Hide resolved

instance(abstract_broker* parent, callee& lstnr);

/// Handles received data and returns a config for receiving the
/// next data or `none` if an error occurred.
/// next data or `none` if an error occured.
Copy link
Member

Choose a reason for hiding this comment

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

Conflict with that spelling PR, i guess.

Suggested change
/// next data or `none` if an error occured.
/// Next data or `none` if an error occurred.

@@ -352,6 +366,11 @@ void middleman::init(actor_system_config& cfg) {
return sec::no_such_group_module;
}

error_code<sec> load(binary_deserializer&, group&) override {
// never called, because we hand out group instances of the local module
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// never called, because we hand out group instances of the local module
// Never called, because we hand out group instances of the local module.

libcaf_core/caf/binary_serializer.hpp Show resolved Hide resolved
Neverlord and others added 3 commits November 23, 2019 09:49
@Neverlord Neverlord merged commit 3e3c947 into master Nov 23, 2019
@Neverlord Neverlord deleted the topic/serialization branch November 23, 2019 09:29
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.

None yet

2 participants