High memory traffic because of boxed SqlGuid struct
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 72
Description
### Is your feature request related to a problem? Please describe.
When our application is starting it loads a lot of data from DB and it causes memory consumption growth and high pressure to GC because of big memory traffic.
On the third place of killed objects is boxed `System.Data.SqlTypes.SqlGuid` struct.
These boxed values are 99.9% created when `TdsParser` is putting `SqlGuid` struct to `SqlBuffer.SqlGuid` property (see the image bellow).

### Describe the solution you'd like
`SqlBuffer` already supports an efficient way to store `Guid` values. What I would like to do is:
- change implementation of `Microsoft.Data.SqlClient.SqlBuffer`
- ~~remove `SqlGuid` value from `StorageType` enum~~ (taking the second alternative approach, removing of `SqlGuid` value from enum looks like a bad idea);
- save `Guid` representation of `SqlGuid` to `_value._guid` (similar to what `Guid` setter does, but with checking if `SqlGuid` value is null)
- read `SqlGuid` value from `_value._guid`
### Describe alternatives you've considered
1. add a field of `SqlGuid` type to `SqlBuffer`, but it seems memory inefficient
2. same as the main approach, but without removing `SqlGuid` value from `StorageType` enum, in case it is really important. The only place where it looks important to me is `s_dbTypeToStorageType` mapping array in `Microsoft.Data.SqlClient.Server.ValueUtilsSmi`, and I am not sure if it is safe to change the mapping to `SqlBuffer.StorageType.Guid`. It seems like it is not safe, because implementation of `SqlBuffer.Guid` does not support nulls.
### Additional context
- Microsoft.Data.SqlClient version is 5.1.0;
- We use Microsoft.Data.SqlClient together with NHibernate;
- Almost all our db tables contain Guid columns, so, memory traffic is really high in our case.
Contributor guide
Assessment
This issue has not been assessed yet.