Optimization: Use CollectionsMarshal.GetValueRefOrAddDefault() for Dictionary operations#487
Optimization: Use CollectionsMarshal.GetValueRefOrAddDefault() for Dictionary operations#487SergeiPavlov wants to merge 1 commit into
CollectionsMarshal.GetValueRefOrAddDefault() for Dictionary operations#487Conversation
…Dictionary operations
Could you give an example of misusing of this pattern?
The |
botinko
left a comment
There was a problem hiding this comment.
This is low-level optimization. It worth adding it to hot-path only, not as a defult option. Let's remove it from ModelBuilder, and other non-hot path places.
I consider all DO code as performance-critical. |
I'm not disagree, but to be honest nano-second optimization does nothing (0.000001%) in this direction. @SergeiPavlov Optimization has no real bechmarks / perf traces / other provable justification. In such cases I accept only 100% safe + code quality-improving changes OR obviously impactful optimizations. From my perspective this is a insignificant nano-second optimizations, that complicates the code without any justification. Current approach of optimization of low-hanging fruites or by the method of the intense gaze is unfocused and unligned with real behaviour on prod. Optimizations based on performance profiling traces will amplify your impact X100. |
This approach typically is the most effective |
The danger is that operations over references are not considered safe in .NET in general. It's hard to forget about checking them for null, and references should be treated in a special way using
By The same idea is why we don't use |
This is not more dangerous than forgetting for null-checking of any reference. |
No description provided.