Skip to content

refactor: serialization simplifications#28203

Merged
fanquake merged 6 commits into
bitcoin:masterfrom
martinus:2023-08-simplify-serialization
Aug 4, 2023
Merged

refactor: serialization simplifications#28203
fanquake merged 6 commits into
bitcoin:masterfrom
martinus:2023-08-simplify-serialization

Conversation

@martinus

@martinus martinus commented Aug 2, 2023

Copy link
Copy Markdown
Contributor

This simplifies the serialization code a bit and should also make it a bit faster.

  • use fold expressions instead of recursive calls. This simplifies the code, makes it most likely faster because it reduces the number of function calls, and compiles faster because there are fewer template instantiations.

  • use if constexpr instead of unnecessarily creating a temporary object only to call the right overload. This is used for std::vector and prevector serialization.

@DrahtBot

DrahtBot commented Aug 2, 2023

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK MarcoFalke, jonatack, sipa, john-moffett

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@jonatack jonatack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a very nice cleanup (and in a widely included and large file).

Have started running a node on this branch.

Initial approach ACK 513f4659b0a2ac4e2454ad2425b0fec8d7f64f04

Comment thread src/serialize.h Outdated

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

very nice, ACK 513f4659b0a2ac4e2454ad2425b0fec8d7f64f04 🙊

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: very nice, ACK 513f4659b0a2ac4e2454ad2425b0fec8d7f64f04 🙊
GEzCyPu57ooJeHDaJ2Nuwgozpyvft2GzjmZzH1LsuCmxm4NLtc+ONqj570HEbSuzwFAnZ/pZOvN9NSTjIWsxDw==

Comment thread src/serialize.h Outdated
Comment thread src/serialize.h Outdated
Comment thread src/serialize.h Outdated

@maflcko maflcko Aug 3, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

review note in 10105d97f412cc54ba4031c56538f7e0c611251f: A simple is_same_v works, because I presume T can never include const in a prevector, similar to how std::vector<const int> does not exist.

…eMany()

Instead of recursively calling `SerializeMany` and peeling off one
argument at a time, use a fold expression. This simplifies the code,
makes it most likely faster because it reduces the number of function
calls, and compiles faster because there are fewer template
instantiations.
…izeMany()

Instead of recursively calling `UnserializeMany` and peeling off one
argument at a time, use a fold expression. This simplifies the code,
makes it most likely faster because it reduces the number of function
calls, and compiles faster because there are fewer template
instantiations.
This gets rid of unnecessarily creating a temporary object T() to call
the right function.
This gets rid of unnecessarily creating a temporary object T() to call
the right function.
This gets rid of unnecessarily creating a temporary object T() to call
the right function.
This gets rid of unnecessarily creating a temporary object T() to call
the right function.
@fanquake fanquake requested a review from john-moffett August 3, 2023 08:35
@martinus martinus force-pushed the 2023-08-simplify-serialization branch from 513f465 to f054bd0 Compare August 3, 2023 08:46
@martinus

martinus commented Aug 3, 2023

Copy link
Copy Markdown
Contributor Author

Rebased to f054bd0 to clang-format the changes, and adds back the && in UnserializeMany.

@maflcko

maflcko commented Aug 3, 2023

Copy link
Copy Markdown
Member

only change is to add a missing &. lgtm, re-ACK f054bd0 📦

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: only change is to add a missing `&`. lgtm, re-ACK f054bd072afb72d8dae7adc521ce15c13b236700 📦
qVTNWRmP4fK55EiOWjNDYq7LnIwUAwWHe96FjQdkKJV0imPWgVxuLQVRwAbyPEiKRxWUArJKVfajpftB3UDzCw==

@DrahtBot DrahtBot requested a review from jonatack August 3, 2023 12:01
@jonatack

jonatack commented Aug 3, 2023

Copy link
Copy Markdown
Member

ACK f054bd0

@DrahtBot DrahtBot removed the request for review from jonatack August 3, 2023 17:47
@sipa

sipa commented Aug 3, 2023

Copy link
Copy Markdown
Member

utACK f054bd0

@john-moffett john-moffett left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK f054bd0

@fanquake fanquake merged commit f138422 into bitcoin:master Aug 4, 2023
@martinus martinus deleted the 2023-08-simplify-serialization branch August 4, 2023 15:38
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 9, 2023
f054bd0 refactor: use "if constexpr" in std::vector's Unserialize() (Martin Leitner-Ankerl)
088caa6 refactor: use "if constexpr" in std::vector's Serialize() (Martin Leitner-Ankerl)
0fafaca refactor: use "if constexpr" in prevector's Unserialize() (Martin Leitner-Ankerl)
c8839ec refactor: use "if constexpr" in prevector's Serialize() (Martin Leitner-Ankerl)
1403d18 refactor: use fold expressions instead of recursive calls in UnserializeMany() (Martin Leitner-Ankerl)
bd08a00 refactor: use fold expressions instead of recursive calls in SerializeMany() (Martin Leitner-Ankerl)

Pull request description:

  This simplifies the serialization code a bit and should also make it a bit faster.

  * use fold expressions instead of recursive calls. This simplifies the code, makes it most likely faster because it reduces the number of function calls, and compiles faster because there are fewer template instantiations.

  * use `if constexpr` instead of unnecessarily creating a temporary object only to call the right overload. This is used for `std::vector` and `prevector` serialization.

ACKs for top commit:
  MarcoFalke:
    only change is to add a missing `&`. lgtm, re-ACK f054bd0 📦
  jonatack:
    ACK f054bd0
  sipa:
    utACK f054bd0
  john-moffett:
    ACK f054bd0

Tree-SHA512: 0417bf2d6be486c581732297945449211fc3481bac82964e27628b38ef55a47dfa58d730148aeaf1b19fa8eb1076489cc646ceebb178162a9afa59034601501d
@bitcoin bitcoin locked and limited conversation to collaborators Aug 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants