Add a custom InterpolatedStringHandler to handle allocation free sql and parameter collection #28
Labels
area:reflow
Any issues targeting reflow
breaking change
An enhancement that will introduce a breaking change to the existing API
enhancement
New feature or request
Milestone
Definition
The purpose of this handler should be to replace the old usage of the
FormattableString
, which worked and required way less code, however the memory allocation was quite immense.With the new custom string interpolation we got with .NET 6 and C# 10 we can reduce the amount allocation of heap allocations to exactly 0. Not only are we avoiding the boxing of value type parameters, but also the allocations of the
FormattableString
object itself and the Expression Trees, which were required to allow for maintainable SQL.Design
As we enforce that a query through the fluent API has to be inline and the content of the lambda has to be an interpolated string, we can use a
ThreadStatic
variable. Which acts as shared data pool between the query method and theSqlInterpolationHandler
.The data we provide to the string handler will contain the
ParameterIndecies
array which will contain all the locations of the parameters (0 based). This will be required once we add the following syntaxtable => "select * from {table}"
, another array will be required which contains the actual string that will replace the fake data. However this syntax will most likely be implemented inv2.1.0
.Additionally we will be able to give the exact length of the string that the
CommandBuilder
will produce as long as it won't contain any collection parameters.Proposal
Usage
The text was updated successfully, but these errors were encountered: