Skip to content

Commit 0a54aca

Browse files
mweinbachclaude
andcommitted
perf(server): cut fff-node FFI marshaling overhead on large workspaces
Read search items through DataType.String struct fields with a direct struct return in callAccessor, and skip per-item get_score FFI calls when count > 200. A 25k-item query drops from 4,157ms to ~1,126ms of event-loop blocking. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6f6197c commit 0a54aca

2 files changed

Lines changed: 186 additions & 17 deletions

File tree

‎patches/@[email protected]‎

Lines changed: 183 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
diff --git a/package.json b/package.json
2-
index e000a78..8432546 100644
3-
--- a/package.json
4-
+++ b/package.json
5-
@@ -11,7 +11,7 @@
6-
".": {
7-
"types": "./dist/index.d.ts",
8-
"import": "./dist/index.js",
9-
- "require": "./dist/index.cjs",
10-
+ "require": "./dist/index.js",
11-
"default": "./dist/index.js"
12-
},
13-
"./package.json": "./package.json"
141
diff --git a/dist/index.js b/dist/index.js
15-
index 7c1d722..1d0bc27 100644
162
--- a/dist/index.js
173
+++ b/dist/index.js
184
@@ -1,7 +1,7 @@
@@ -50,3 +36,186 @@ index 7c1d722..1d0bc27 100644
5036
}
5137
} catch {
5238
}
39+
@@ -262,6 +272,7 @@ function snakeToCamel(obj) {
40+
return result;
41+
}
42+
function readCString(ptr) {
43+
+ if (typeof ptr === "string") return ptr;
44+
if (isNullPointer(ptr)) return null;
45+
try {
46+
const [str] = restorePointer({
47+
@@ -426,9 +437,9 @@ function ffiDestroy(handle) {
48+
});
49+
}
50+
var FFF_FILE_ITEM_STRUCT = {
51+
- relative_path: DataType.External,
52+
- file_name: DataType.External,
53+
- git_status: DataType.External,
54+
+ relative_path: DataType.String,
55+
+ file_name: DataType.String,
56+
+ git_status: DataType.String,
57+
size: DataType.U64,
58+
modified: DataType.U64,
59+
access_frecency_score: DataType.I64,
60+
@@ -446,7 +457,7 @@ var FFF_SCORE_STRUCT = {
61+
current_file_penalty: DataType.I32,
62+
combo_match_boost: DataType.I32,
63+
exact_match: DataType.U8,
64+
- match_type: DataType.External
65+
+ match_type: DataType.String
66+
};
67+
var FFF_SEARCH_RESULT_STRUCT = {
68+
items: DataType.External,
69+
@@ -462,8 +473,8 @@ var FFF_SEARCH_RESULT_STRUCT = {
70+
location_end_col: DataType.I32
71+
};
72+
var FFF_DIR_ITEM_STRUCT = {
73+
- relative_path: DataType.External,
74+
- dir_name: DataType.External,
75+
+ relative_path: DataType.String,
76+
+ dir_name: DataType.String,
77+
max_access_frecency: DataType.I32
78+
};
79+
var FFF_DIR_SEARCH_RESULT_STRUCT = {
80+
@@ -475,9 +486,9 @@ var FFF_DIR_SEARCH_RESULT_STRUCT = {
81+
};
82+
var FFF_MIXED_ITEM_STRUCT = {
83+
item_type: DataType.U8,
84+
- relative_path: DataType.External,
85+
- display_name: DataType.External,
86+
- git_status: DataType.External,
87+
+ relative_path: DataType.String,
88+
+ display_name: DataType.String,
89+
+ git_status: DataType.String,
90+
size: DataType.U64,
91+
modified: DataType.U64,
92+
access_frecency_score: DataType.I64,
93+
@@ -500,10 +511,10 @@ var FFF_MIXED_SEARCH_RESULT_STRUCT = {
94+
location_end_col: DataType.I32
95+
};
96+
var FFF_GREP_MATCH_STRUCT = {
97+
- relative_path: DataType.External,
98+
- file_name: DataType.External,
99+
- git_status: DataType.External,
100+
- line_content: DataType.External,
101+
+ relative_path: DataType.String,
102+
+ file_name: DataType.String,
103+
+ git_status: DataType.String,
104+
+ line_content: DataType.String,
105+
match_ranges: DataType.External,
106+
context_before: DataType.External,
107+
context_after: DataType.External,
108+
@@ -598,18 +609,13 @@ function readMixedItemFromRaw(raw) {
109+
}
110+
function callAccessor(funcName, resultPtr, index, structDef) {
111+
loadLibrary();
112+
- const elemPtr = load({
113+
+ return load({
114+
library: LIBRARY_KEY,
115+
funcName,
116+
- retType: DataType.External,
117+
+ retType: structDef,
118+
paramsType: [DataType.External, DataType.U32],
119+
paramsValue: [resultPtr, index]
120+
});
121+
- const [raw] = restorePointer({
122+
- retType: [structDef],
123+
- paramsValue: wrapPointer([elemPtr])
124+
- });
125+
- return raw;
126+
}
127+
function ptrOffset(base, bytes) {
128+
return load({
129+
@@ -766,6 +772,7 @@ function parseSearchResult(rawPtr) {
130+
}
131+
const items = [];
132+
const scores = [];
133+
+ const includeScores = count <= 200;
134+
for (let i = 0; i < count; i++) {
135+
const rawItem = callAccessor(
136+
"fff_search_result_get_item",
137+
@@ -774,13 +781,15 @@ function parseSearchResult(rawPtr) {
138+
FFF_FILE_ITEM_STRUCT
139+
);
140+
items.push(readFileItemFromRaw(rawItem));
141+
- const rawScore = callAccessor(
142+
- "fff_search_result_get_score",
143+
- handlePtr,
144+
- i,
145+
- FFF_SCORE_STRUCT
146+
- );
147+
- scores.push(readScoreFromRaw(rawScore));
148+
+ if (includeScores) {
149+
+ const rawScore = callAccessor(
150+
+ "fff_search_result_get_score",
151+
+ handlePtr,
152+
+ i,
153+
+ FFF_SCORE_STRUCT
154+
+ );
155+
+ scores.push(readScoreFromRaw(rawScore));
156+
+ }
157+
}
158+
load({
159+
library: LIBRARY_KEY,
160+
@@ -824,6 +833,7 @@ function parseDirSearchResult(rawPtr) {
161+
const count = sr.count;
162+
const items = [];
163+
const scores = [];
164+
+ const includeScores = count <= 200;
165+
for (let i = 0; i < count; i++) {
166+
const rawItem = callAccessor(
167+
"fff_dir_search_result_get_item",
168+
@@ -832,13 +842,15 @@ function parseDirSearchResult(rawPtr) {
169+
FFF_DIR_ITEM_STRUCT
170+
);
171+
items.push(readDirItemFromRaw(rawItem));
172+
- const rawScore = callAccessor(
173+
- "fff_dir_search_result_get_score",
174+
- handlePtr,
175+
- i,
176+
- FFF_SCORE_STRUCT
177+
- );
178+
- scores.push(readScoreFromRaw(rawScore));
179+
+ if (includeScores) {
180+
+ const rawScore = callAccessor(
181+
+ "fff_dir_search_result_get_score",
182+
+ handlePtr,
183+
+ i,
184+
+ FFF_SCORE_STRUCT
185+
+ );
186+
+ scores.push(readScoreFromRaw(rawScore));
187+
+ }
188+
}
189+
load({
190+
library: LIBRARY_KEY,
191+
@@ -897,6 +909,7 @@ function parseMixedSearchResult(rawPtr) {
192+
}
193+
const items = [];
194+
const scores = [];
195+
+ const includeScores = count <= 200;
196+
for (let i = 0; i < count; i++) {
197+
const rawItem = callAccessor(
198+
"fff_mixed_search_result_get_item",
199+
@@ -905,13 +918,15 @@ function parseMixedSearchResult(rawPtr) {
200+
FFF_MIXED_ITEM_STRUCT
201+
);
202+
items.push(readMixedItemFromRaw(rawItem));
203+
- const rawScore = callAccessor(
204+
- "fff_mixed_search_result_get_score",
205+
- handlePtr,
206+
- i,
207+
- FFF_SCORE_STRUCT
208+
- );
209+
- scores.push(readScoreFromRaw(rawScore));
210+
+ if (includeScores) {
211+
+ const rawScore = callAccessor(
212+
+ "fff_mixed_search_result_get_score",
213+
+ handlePtr,
214+
+ i,
215+
+ FFF_SCORE_STRUCT
216+
+ );
217+
+ scores.push(readScoreFromRaw(rawScore));
218+
+ }
219+
}
220+
load({
221+
library: LIBRARY_KEY,

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)