-
Notifications
You must be signed in to change notification settings - Fork 46
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
Value types have increased size and different alignment than base type #498
Comments
Very interesting - thank you for the bug report. One of the main goals of Vogen is to maintain the same (or very similar) performance as the primitive it wraps. I'll take a look at this one to see if the same functionality can be achieved without the local variable. |
Mmm.. please note that I'm actually using the _isInitialized to check for a valid state. Removing that field would render all my VOs unusable (for "reasons" I need to be able to have VOs that are invalid and be able to check that condition before trying to use them, without throwing exceptions). |
To preserve backwards compatibility, a new option that is disabled by default would remove the |
I'm struggling to think of a way where this field could be removed and still retain the safety that (almost) guarantees validity. But it does seem that a flag is the best option, something like |
Hi @CheloXL - in the latest version, there is now an |
How is it possible to make a preference for size over safety?
|
It can be implemented easy and fast (but slightly hacky) [ValueObject<string>]
public readonly struct MyObj
{
private bool _isInitialized => _value != null;
} This hack will allow us to keep most of the existing code generation logic. |
@SteveDunn, can you please have a look at this proposal ? |
Hi, yes, I'll take a look. There's now an IsInitialized method, so I could omit the field and and hardcode that to return true (so that I don't have to change hundreds of other places that expect the method). I think I'm right in assuming that the method won't increase the size of each instance... |
@dmitriyse - this will be in the next release, likely later this week. Thanks again for your feedback |
Thank you a lot, @SteveDunn, for this hard work. As usual, you responded very quickly. |
Describe the bug
Vogen adds a
bool _isInitialized
andStackTrace _stackTrace
field. The latter is only available in debug mode (see #497) but both fields increase the size of the value type and change the alignment, which can result in binary serialization issues and decreased performance.Steps to reproduce
Create a value type:
Compare the sizes (only works in release mode due to #497):
Expected behaviour
These two values should be the same:
An option to remove the
bool _isInitialized
would solve this issue.The text was updated successfully, but these errors were encountered: