ADO.NET API for reading string data directly from the provider's internal buffer #28135
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Data
enhancement
Product code improvement that does NOT require public API changes/additions
Milestone
dotnet/corefxlab#2368 discusses directions and goals for future UTF-8 string support. Apart from a new
UTF8String
type (https://github.com/dotnet/corefx/issues/30503) which would obviate decoding when binary data is already in UTF8, there is also a first discussion on a perf-oriented UTF8 slice directly over binary data:Something like this could be exposed on DbDataReader, returning a string-like object that directly references the ADO.NET provider's internal buffer; this would allow users to do zero-allocation access on incoming strings from the database, with a potentially big perf impact.
The big issue is of course the lifespan of the returned slice object. Unless
CommandBehavior.Sequential
is specified, providers are already expected to buffer entire rows into memory. The lifetime of a string slice would therefore be until the next timeDbDataReader.Read()
is called, at which point the data in the buffer is potentially changed. This is somewhat dangerous and requires understanding from users, so this would definitely be an advanced, high-perf API only.Note the similarity with
DbDataReader.GetStream()
andDbDataReader.GetTextReader()
, which are used to stream (large) binary and text data from the database. Although not formally specified, it is expected for the returnedStream
/TextReader
to be disposed as soon as the next row is read. It could be interesting to think of some sort of "invalidatable slice", where callingDbDataReader.Read()
would invalidate any string slice returned on the previous row.Such automatically-invalidated slices could be of interest as a safety measure anywhere where we're considering exposing slices to end users, where underlying data could change.
/cc @GrabYourPitchforks @divega @ajcvickers
The text was updated successfully, but these errors were encountered: