Skip to content

Commit 871bc75

Browse files
committed
deterministic profiler output and search efficiency
- addresses latest feedback for PR #119 ; - profile-codeql-query-from-logs: remove non-deterministic `Generated:` timestamp from detail file header to ensure reproducible output for integration test fixtures ; - search-ql-code: early-exit file processing once maxResults matches are collected; subsequent files are scanned cheaply for totalMatches count only, avoiding large array allocations and context extraction ;
1 parent fad2f61 commit 871bc75

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

client/integration-tests/primitives/tools/profile_codeql_query_from_logs/multi_query_raw_log/after/query-evaluation-detail.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CodeQL Evaluator Profile — Predicate Detail
2-
# Generated: 2026-03-10T14:57:38.405Z
2+
# Generated: 2026-03-10T18:36:19.438Z
33
# Log format: raw
44
# CodeQL version: 2.23.1
55
# Use read_file with line ranges from the JSON response to access individual predicates.

client/integration-tests/primitives/tools/profile_codeql_query_from_logs/single_query_raw_log/after/query-evaluation-detail.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CodeQL Evaluator Profile — Predicate Detail
2-
# Generated: 2026-03-10T14:57:38.415Z
2+
# Generated: 2026-03-10T18:36:19.453Z
33
# Log format: raw
44
# CodeQL version: 2.23.1
55
# Use read_file with line ranges from the JSON response to access individual predicates.

server/dist/codeql-development-mcp-server.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61796,7 +61796,6 @@ function buildDetailFile(profile, topN) {
6179661796
const lines = [];
6179761797
const lineIndex = /* @__PURE__ */ new Map();
6179861798
lines.push("# CodeQL Evaluator Profile \u2014 Predicate Detail");
61799-
lines.push(`# Generated: ${(/* @__PURE__ */ new Date()).toISOString()}`);
6180061799
lines.push(`# Log format: ${profile.logFormat}`);
6180161800
if (profile.codeqlVersion) {
6180261801
lines.push(`# CodeQL version: ${profile.codeqlVersion}`);
@@ -63055,14 +63054,32 @@ async function searchQlCode(params) {
6305563054
const filesToSearch = collectFiles(paths, includeExtensions, fileCount);
6305663055
const allMatches = [];
6305763056
let totalMatches = 0;
63057+
let collectedEnough = false;
6305863058
for (const file of filesToSearch) {
63059+
if (collectedEnough) {
63060+
try {
63061+
const st = lstatSync(file);
63062+
if (!st.isFile()) continue;
63063+
const content = st.size <= MAX_FILE_SIZE_BYTES ? readFileSync9(file, "utf-8") : null;
63064+
if (content) {
63065+
for (const line of content.replace(/\r\n/g, "\n").split("\n")) {
63066+
if (regex.test(line)) totalMatches++;
63067+
}
63068+
}
63069+
} catch {
63070+
}
63071+
continue;
63072+
}
6305963073
const fileMatches = await searchFile(file, regex, contextLines);
6306063074
totalMatches += fileMatches.length;
6306163075
for (const m of fileMatches) {
6306263076
if (allMatches.length < maxResults) {
6306363077
allMatches.push(m);
6306463078
}
6306563079
}
63080+
if (allMatches.length >= maxResults) {
63081+
collectedEnough = true;
63082+
}
6306663083
}
6306763084
return {
6306863085
results: allMatches,

server/dist/codeql-development-mcp-server.js.map

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

server/src/tools/codeql/profile-codeql-query-from-logs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ function buildDetailFile(
108108
const lineIndex = new Map<string, { start: number; end: number }>();
109109

110110
lines.push('# CodeQL Evaluator Profile — Predicate Detail');
111-
lines.push(`# Generated: ${new Date().toISOString()}`);
112111
lines.push(`# Log format: ${profile.logFormat}`);
113112
if (profile.codeqlVersion) {
114113
lines.push(`# CodeQL version: ${profile.codeqlVersion}`);

server/src/tools/codeql/search-ql-code.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,29 @@ export async function searchQlCode(params: {
288288

289289
const allMatches: SearchMatch[] = [];
290290
let totalMatches = 0;
291+
let collectedEnough = false;
291292

292293
for (const file of filesToSearch) {
294+
if (collectedEnough) {
295+
// Still need totalMatches count but skip storing results.
296+
// For small files, just count line matches without allocating.
297+
try {
298+
const st = lstatSync(file);
299+
if (!st.isFile()) continue;
300+
const content = st.size <= MAX_FILE_SIZE_BYTES
301+
? readFileSync(file, 'utf-8')
302+
: null;
303+
if (content) {
304+
for (const line of content.replace(/\r\n/g, '\n').split('\n')) {
305+
if (regex.test(line)) totalMatches++;
306+
}
307+
}
308+
} catch {
309+
// skip
310+
}
311+
continue;
312+
}
313+
293314
const fileMatches = await searchFile(file, regex, contextLines);
294315
totalMatches += fileMatches.length;
295316

@@ -298,6 +319,10 @@ export async function searchQlCode(params: {
298319
allMatches.push(m);
299320
}
300321
}
322+
323+
if (allMatches.length >= maxResults) {
324+
collectedEnough = true;
325+
}
301326
}
302327

303328
return {

0 commit comments

Comments
 (0)