-
Notifications
You must be signed in to change notification settings - Fork 15
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
Maybe<T> have reference to Option<T> instance #38
Comments
Unfortunately, just removing the reference wouldn't achieve much as many features of Succinc<T> return an To properly address this, those features would need to change to return |
I'd suggest to write performance benchmark tests first. For example, introduction of singleton value for Option.None() cases significantly improved performance of our code which was creating tens of thousands of those objects. I'm pretty sure turning Option into structs will increase the overhead of passing them around. |
Good point, @megafinz. I shall do that. |
@megafinz as a general rule, small enough structs are considered better than small classes for performance purposes.
Often that overhead can be mitigated via passing structs by ref. |
Good point, thanks, that simplifies things quite a bit. |
I'm uncomfortable with the idea of having to replace classes with structs and lots of ref returns as I feel that would complicate things, just to provide performance enhancements. But I shall experiment once v3.1 is released. Of course, if either you or @megafinz wish to submit any performance tests for me to base my experiments on, then those PR's will be very gratefully received, as performance testing is not a strong point for me. |
@DavidArno I propose to have two versions of it. After all, there are
Generally small enough structs such as |
|
https://github.com/DavidArno/SuccincT/blob/master/src/SuccincT/Options/Maybe%7BT%7D.cs
Although
Maybe<T>
appears as struct, it have internal reference to instance of reference typeMajor purpose of structs isn't to avoid "Null reference exceptions". Major purpose of structs is to avoid memory allocations on heap which can be critical under heavy load.
Option<T>
andMaybe<T>
are small enough to be structs as heap allocations and then GC to release references are more performance-impacting than copy of such small structs around.Maybe<T>
retain unnecessary GC handle (internal reference-type instance ofOption<T>
), so it don't provide performance benefits of structs.The text was updated successfully, but these errors were encountered: