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

Replace casts/assignments with hard-coded memcpy operations #2863

Merged
merged 1 commit into from Aug 29, 2017

Conversation

hkaiser
Copy link
Member

@hkaiser hkaiser commented Aug 27, 2017

No description provided.

break;

case 2:
*static_cast<std::uint16_t*>(dest) =
*static_cast<std::uint16_t const*>(address);
std::memcpy(dest, address, 2);
Copy link
Member

@taeguk taeguk Aug 28, 2017

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

@taeguk taeguk Aug 28, 2017

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?

Copy link
Member Author

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.

Copy link
Member

@sithhell sithhell left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@sithhell sithhell merged commit 48d2b38 into master Aug 29, 2017
@sithhell sithhell deleted the serialization branch August 29, 2017 06:19
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

3 participants