[struct_pack] enhance serialize performance by uninitialized resize #489
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
In old version, if struct_pack save binary to a container, it will call member function
resize()
. which cause useless initialization.What is changing
Add a helper function
struct_pack::detail::resize()
, which will resize some container(std::basic_string<char/unsigned char/signed char>, std::vector<char/unsigned char/signed char/std::byte>) without initialization.In benchmark:
old version:
new version:
If the person's name field length is 10000(almost all data are string)
old version:
new version:
So in best case, struct_pack serialization is 1.4x faster than old version if you save your struct to std::vector/std::string
There is no change if you save your struct to stream/raw pointer.