fix: remove redundant metricModel reassignment and per-statement DB query metrics

- Remove duplicate assignment of metricModel in ProviderService.sendTurn
  (line 419 was identical to line 411, input is never mutated between them)
- Remove withMetrics wrapper from individual SQLite runStatement/runValues
  to eliminate per-query overhead (generator alloc, exit boxing, timestamps,
  metric attribute construction) on the hot path for sub-millisecond queries
This commit is contained in:
Cursor Agent committed 2026-04-03 02:31:22 +00:00
1 parent 8cc42335ed
commit 776d8b4943
2 files changed
+1 -20

No files matched your search

@@ -23,8 +23,6 @@ import type { Connection } from "effect/unstable/sql/SqlConnection";
import { SqlError, classifySqliteError } from "effect/unstable/sql/SqlError";
import * as Statement from "effect/unstable/sql/Statement";
import { dbQueriesTotal, dbQueryDuration, withMetrics } from "../observability/Metrics.ts";
const ATTR_DB_SYSTEM_NAME = "db.system.name";
export const TypeId: TypeId = "~local/sqlite-node/SqliteClient";
@@ -84,9 +82,6 @@ const makeWithDatabase = Effect.fn("makeWithDatabase")(function* (
const transformRows = options.transformResultNames
? Statement.defaultTransforms(options.transformResultNames).array
: undefined;
const databaseMetricAttributes = {
database: options.filename === ":memory:" ? "memory" : "disk",
} as const;
const makeConnection = Effect.gen(function* () {
const scope = yield* Effect.scope;
@@ -142,13 +137,7 @@ const makeWithDatabase = Effect.fn("makeWithDatabase")(function* (
}),
);
}
}).pipe(
withMetrics({
counter: dbQueriesTotal,
timer: dbQueryDuration,
attributes: databaseMetricAttributes,
}),
);
});
const run = (sql: string, params: ReadonlyArray<unknown>, raw = false) =>
Effect.flatMap(Cache.get(prepareCache, sql), (s) => runStatement(s, params, raw));
@@ -161,7 +150,6 @@ const makeWithDatabase = Effect.fn("makeWithDatabase")(function* (
try: () => {
if (hasRows(statement)) {
statement.setReturnArrays(true);
// Safe to cast to array after we've setReturnArrays(true)
return statement.all(...(params as any)) as unknown as ReadonlyArray<
ReadonlyArray<unknown>
>;
@@ -183,12 +171,6 @@ const makeWithDatabase = Effect.fn("makeWithDatabase")(function* (
statement.setReturnArrays(false);
}
}),
).pipe(
withMetrics({
counter: dbQueriesTotal,
timer: dbQueryDuration,
attributes: databaseMetricAttributes,
}),
);
return identity<Connection>({
@@ -416,7 +416,6 @@ const makeProviderService = Effect.fn("makeProviderService")(function* (
allowRecovery: true,
});
metricProvider = routed.adapter.provider;
metricModel = input.modelSelection?.model;
yield* Effect.annotateCurrentSpan({
"provider.kind": routed.adapter.provider,
...(input.modelSelection?.model ? { "provider.model": input.modelSelection.model } : {}),