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

Empty etl::optional ctor storage initialization performance #626

Closed
mkalibat opened this issue Oct 18, 2022 · 3 comments
Closed

Empty etl::optional ctor storage initialization performance #626

mkalibat opened this issue Oct 18, 2022 · 3 comments
Assignees

Comments

@mkalibat
Copy link

Hi,

This PR added initialization of etl::optional's storage buffer in the empty-state constructors to avoid compiler warnings.

A problem with this is that now constructing optionals in the empty state requires value initialization (rather than trivial default construction, which "performs no action") of the storage buffer to 0's, which can be quite inefficient in some cases. (See Explanation 3 and Trivial default constructor):

See https://godbolt.org/z/jMd59sc9T.

Looking at the std::optional implementations, it looks like some zero-initialize the storage and some don't.

I'm not sure what the best solution is here; being warning-clean is essential, but the extra overhead of the zero-init can be substantial. In my case, this causes ~10% CPU overhead during fairly frequently executed operations when using a not-very-large optional (~36B). I can work around it locally, but it may be a surprising performance hit for users in general. I suppose the [[maybe_unused]] attribute might be used to suppress the warnings, but that's C++17.

Any thoughts? Thanks.

@jwellbelove
Copy link
Contributor

I think there are a couple of other classes that do the same as etl::optional to suppress warnings. I may need to disable that warning for the constructors.

@mkalibat
Copy link
Author

Great, thanks for taking a look!

@jwellbelove
Copy link
Contributor

Fixed 20.35.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants