qicosmos / iguana

universal serialization engine
Apache License 2.0
1.11k stars 226 forks source link

[struct_pb] performance #301

Closed qicosmos closed 1 month ago

qicosmos commented 2 months ago
struct RepeatIguanaTypeMsg : public iguana::base_impl<RepeatIguanaTypeMsg> {
  RepeatIguanaTypeMsg() = default;
  RepeatIguanaTypeMsg(std::vector<iguana::sfixed32_t> a,
                      std::vector<iguana::sfixed64_t> b,
                      std::vector<iguana::fixed32_t> c,
                      std::vector<iguana::fixed64_t> d,
                      std::vector<iguana::sfixed32_t> e,
                      std::vector<iguana::sfixed64_t> f)
      : repeated_sint32(std::move(a)),
        repeated_sint64(std::move(b)),
        repeated_fixed32(std::move(c)),
        repeated_fixed64(std::move(d)),
        repeated_sfixed32(std::move(e)),
        repeated_sfixed64(std::move(f)) {}
  std::vector<iguana::sfixed32_t> repeated_sint32;
  std::vector<iguana::sfixed64_t> repeated_sint64;
  std::vector<iguana::fixed32_t> repeated_fixed32;
  std::vector<iguana::fixed64_t> repeated_fixed64;
  std::vector<iguana::sfixed32_t> repeated_sfixed32;
  std::vector<iguana::sfixed64_t> repeated_sfixed64;
};

REFLECTION(RepeatIguanaTypeMsg, repeated_sint32, repeated_sint64,
         repeated_fixed32, repeated_fixed64, repeated_sfixed32,
         repeated_sfixed64);

  RepeatIguanaTypeMsg re_iguana_type_st{
      {{0}, {1}, {3}},    {{4}, {5}, {6}},    {{7}, {8}, {9}},
      {{10}, {11}, {12}}, {{13}, {14}, {15}}, {},
  };

from_pb is slower than pb::RepeatIguanaTypeMsg ParseFromString.

Need to improve.

bbbgan commented 1 month ago

Potential performance improvement found:

When parsing fixed types, pb directly copies the data into the array (see protobuf source code).

While iguana first copies the data into a number and then pushes it back into the array, resulting in an extra copy operation.

To be improved later.