Skip to content

Commit add2e51

Browse files
perf: cache Type.GetType calls in VerifyResultsetColumns
Eliminates repeated Type.GetType reflection calls during result set verification by caching resolved types in a ConcurrentDictionary. Before: Type.GetType was called for every column in every result set on every query execution when runtime verification is enabled. After: Type resolution happens once per unique type name and is cached for subsequent queries. Impact: Significantly reduces reflection overhead in verification path, especially for queries with many columns or high execution frequency. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f8a4561 commit add2e51

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/SqlClient/ISqlCommand.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
127127

128128
| unexpected -> failwithf "Unexpected ResultType value: %O" unexpected
129129

130+
static let typeCache = System.Collections.Concurrent.ConcurrentDictionary<string, Type>()
131+
130132
member this.CommandTimeout = cmd.CommandTimeout
131133

132134
interface ISqlCommand with
@@ -262,7 +264,8 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
262264
invalidOp message
263265

264266
for i = 0 to expected.Length - 1 do
265-
let expectedName, expectedType = fst expected.[i], Type.GetType( snd expected.[i], throwOnError = true)
267+
let expectedName, expectedTypeString = fst expected.[i], snd expected.[i]
268+
let expectedType = typeCache.GetOrAdd(expectedTypeString, fun typeName -> Type.GetType(typeName, throwOnError = true))
266269
let actualName, actualType = cursor.GetName( i), cursor.GetFieldType( i)
267270
if actualName <> expectedName || actualType <> expectedType
268271
then

0 commit comments

Comments
 (0)