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
Replace casts/assignments with hard-coded memcpy operations #2863
Conversation
break; | ||
|
||
case 2: | ||
*static_cast<std::uint16_t*>(dest) = | ||
*static_cast<std::uint16_t const*>(address); | ||
std::memcpy(dest, address, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, std::memcpy
is performed in default:
. So, as I think, there is no need to handle separately in each different cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of repeating the memcpy()
invocations with constant byte sizes is that compilers usually optimize those, whereas the generic memcpy(d, s, N)
can't be optimized as aggressively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hkaiser Oh, makes sense! I got it 👍 You're right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hkaiser Does the benefit of compiler optimizations exceed the overhead of switch-case statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The measurements show that serialization is up to 10% faster with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
No description provided.