Skip to content

Commit 60c2b93

Browse files
remove zod parsing altogether
1 parent 029cad8 commit 60c2b93

4 files changed

Lines changed: 8 additions & 24 deletions

File tree

packages/web/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"@codemirror/search": "^6.5.6",
5252
"@codemirror/state": "^6.4.1",
5353
"@codemirror/view": "^6.33.0",
54-
"@duplojs/zod-accelerator": "^2.6.2",
5554
"@floating-ui/react": "^0.27.2",
5655
"@hookform/resolvers": "^3.9.0",
5756
"@iconify/react": "^5.1.0",

packages/web/src/features/search/searchApi.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22

33
import { sew } from "@/actions";
44
import { withOptionalAuthV2 } from "@/withAuthV2";
5-
import { ZodAccelerator } from "@duplojs/zod-accelerator";
65
import { PrismaClient, Repo } from "@sourcebot/db";
76
import { base64Decode, createLogger } from "@sourcebot/shared";
87
import { StatusCodes } from "http-status-codes";
9-
import z from "zod";
108
import { ErrorCode } from "../../lib/errorCodes";
119
import { invalidZoektResponse, ServiceError } from "../../lib/serviceError";
1210
import { isServiceError, measure } from "../../lib/utils";
1311
import { SearchRequest, SearchResponse, SourceRange } from "./types";
1412
import { zoektFetch } from "./zoektClient";
15-
import { zoektSearchResponseSchema } from "./zoektSchema";
13+
import { ZoektSearchResponse } from "./zoektSchema";
1614

17-
const acceleratedZoektSearchResponseSchema = ZodAccelerator.build(zoektSearchResponseSchema);
1815
const logger = createLogger("searchApi");
1916

2017
// List of supported query prefixes in zoekt.
@@ -220,7 +217,7 @@ export const search = async ({ query, matches, contextLines, whole }: SearchRequ
220217
return invalidZoektResponse(searchResponse);
221218
}
222219

223-
const transformZoektSearchResponse = async ({ Result }: z.infer<typeof zoektSearchResponseSchema>) => {
220+
const transformZoektSearchResponse = async ({ Result }: ZoektSearchResponse) => {
224221
// @note (2025-05-12): in zoekt, repositories are identified by the `RepositoryID` field
225222
// which corresponds to the `id` in the Repo table. In order to efficiently fetch repository
226223
// metadata when transforming (potentially thousands) of file matches, we aggregate a unique
@@ -394,25 +391,22 @@ export const search = async ({ query, matches, contextLines, whole }: SearchRequ
394391
false
395392
);
396393

397-
const { data: zoektResponse, durationMs: parseZoektResponseDurationMs } = await measure(
398-
() => acceleratedZoektSearchResponseSchema.parseAsync(rawZoektResponse),
399-
"parse_zoekt_response",
400-
false
401-
);
394+
// @note: We do not use zod parseAsync here since in cases where the
395+
// response is large (> 40MB), there can be significant performance issues.
396+
const zoektResponse = rawZoektResponse as ZoektSearchResponse;
402397

403398
const { data: response, durationMs: transformZoektResponseDurationMs } = await measure(
404399
() => transformZoektSearchResponse(zoektResponse),
405400
"transform_zoekt_response",
406401
false
407402
);
408403

409-
const totalDurationMs = fetchDurationMs + parseJsonDurationMs + parseZoektResponseDurationMs + transformZoektResponseDurationMs;
404+
const totalDurationMs = fetchDurationMs + parseJsonDurationMs + transformZoektResponseDurationMs;
410405

411406
// Debug log: timing breakdown
412407
const timings = [
413408
{ name: "zoekt_fetch", duration: fetchDurationMs },
414409
{ name: "parse_json", duration: parseJsonDurationMs },
415-
{ name: "parse_zoekt_response", duration: parseZoektResponseDurationMs },
416410
{ name: "transform_zoekt_response", duration: transformZoektResponseDurationMs },
417411
];
418412

@@ -430,7 +424,6 @@ export const search = async ({ query, matches, contextLines, whole }: SearchRequ
430424
__debug_timings: {
431425
zoekt_fetch: fetchDurationMs,
432426
parse_json: parseJsonDurationMs,
433-
parse_zoekt_response: parseZoektResponseDurationMs,
434427
transform_zoekt_response: transformZoektResponseDurationMs,
435428
}
436429
} satisfies SearchResponse;

packages/web/src/features/search/zoektSchema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export const zoektSearchResponseSchema = z.object({
7575
}),
7676
});
7777

78+
export type ZoektSearchResponse = z.infer<typeof zoektSearchResponseSchema>;
79+
7880
// @see : https://github.com/sourcebot-dev/zoekt/blob/3780e68cdb537d5a7ed2c84d9b3784f80c7c5d04/api.go#L728
7981
const zoektRepoStatsSchema = z.object({
8082
Repos: z.number(),

yarn.lock

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,15 +1630,6 @@ __metadata:
16301630
languageName: node
16311631
linkType: hard
16321632

1633-
"@duplojs/zod-accelerator@npm:^2.6.2":
1634-
version: 2.6.2
1635-
resolution: "@duplojs/zod-accelerator@npm:2.6.2"
1636-
peerDependencies:
1637-
zod: ">=3.0.0 <4.0.0"
1638-
checksum: 10c0/9b8a1dd6cc7c79df16d6e82b34a3f9f76242f513bb272265adbf159f565785f7c4be14d9cf492053fbacd806d0865b20ce1e9adff28f92f7ff9730121688e2b5
1639-
languageName: node
1640-
linkType: hard
1641-
16421633
"@emnapi/core@npm:^1.3.1":
16431634
version: 1.3.1
16441635
resolution: "@emnapi/core@npm:1.3.1"
@@ -8067,7 +8058,6 @@ __metadata:
80678058
"@codemirror/search": "npm:^6.5.6"
80688059
"@codemirror/state": "npm:^6.4.1"
80698060
"@codemirror/view": "npm:^6.33.0"
8070-
"@duplojs/zod-accelerator": "npm:^2.6.2"
80718061
"@eslint/eslintrc": "npm:^3"
80728062
"@floating-ui/react": "npm:^0.27.2"
80738063
"@hookform/resolvers": "npm:^3.9.0"

0 commit comments

Comments
 (0)