-
Notifications
You must be signed in to change notification settings - Fork 15
fix+perf: dogfood fixes 9.1-9.4 and sub-100ms incremental rebuilds #640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
253e3a7
8e43e43
b60fbb7
54c6c18
5eeb0dc
9b469df
e3eb0e5
c3ccbdd
4eceebd
64c1565
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,15 @@ | |
| import { createHash } from 'node:crypto'; | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import type BetterSqlite3 from 'better-sqlite3'; | ||
| import { purgeFilesData } from '../../../db/index.js'; | ||
| import { warn } from '../../../infrastructure/logger.js'; | ||
| import { debug, warn } from '../../../infrastructure/logger.js'; | ||
| import { EXTENSIONS, IGNORE_DIRS } from '../../../shared/constants.js'; | ||
| import type { BetterSqlite3Database, CodegraphConfig, PathAliases } from '../../../types.js'; | ||
| import type { | ||
| BetterSqlite3Database, | ||
| CodegraphConfig, | ||
| PathAliases, | ||
| SqliteStatement, | ||
| } from '../../../types.js'; | ||
|
|
||
| export const BUILTIN_RECEIVERS: Set<string> = new Set([ | ||
| 'console', | ||
|
|
@@ -149,7 +153,7 @@ export function loadPathAliases(rootDir: string): PathAliases { | |
| } | ||
| break; | ||
| } catch (err: unknown) { | ||
| warn(`Failed to parse ${configName}: ${(err as Error).message}`); | ||
| debug(`Failed to parse ${configName}: ${(err as Error).message}`); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The log level for a failed If the intent is to suppress noise when a project simply has no tsconfig (the path does not exist, so JSON.parse throws), a tighter fix would be to distinguish a parse error from a missing-file error and only demote the latter: } catch (err: unknown) {
const msg = (err as Error).message;
// Suppress "no such file" noise; surface genuine parse errors
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
debug(`Config not found: ${configName}`);
} else {
warn(`Failed to parse ${configName}: ${msg}`);
}
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. The |
||
| } | ||
| } | ||
| return aliases; | ||
|
|
@@ -199,7 +203,7 @@ export function readFileSafe(filePath: string, retries: number = 2): string { | |
| * Purge all graph data for the specified files. | ||
| */ | ||
| export function purgeFilesFromGraph( | ||
| db: BetterSqlite3.Database, | ||
| db: BetterSqlite3Database, | ||
| files: string[], | ||
| options: Record<string, unknown> = {}, | ||
| ): void { | ||
|
|
@@ -211,10 +215,10 @@ export function purgeFilesFromGraph( | |
| const BATCH_CHUNK = 500; | ||
|
|
||
| // Statement caches keyed by chunk size — avoids recompiling for every batch. | ||
| const nodeStmtCache = new WeakMap<BetterSqlite3.Database, Map<number, BetterSqlite3.Statement>>(); | ||
| const edgeStmtCache = new WeakMap<BetterSqlite3.Database, Map<number, BetterSqlite3.Statement>>(); | ||
| const nodeStmtCache = new WeakMap<BetterSqlite3Database, Map<number, SqliteStatement>>(); | ||
| const edgeStmtCache = new WeakMap<BetterSqlite3Database, Map<number, SqliteStatement>>(); | ||
|
|
||
| function getNodeStmt(db: BetterSqlite3.Database, chunkSize: number): BetterSqlite3.Statement { | ||
| function getNodeStmt(db: BetterSqlite3Database, chunkSize: number): SqliteStatement { | ||
| let cache = nodeStmtCache.get(db); | ||
| if (!cache) { | ||
| cache = new Map(); | ||
|
|
@@ -232,7 +236,7 @@ function getNodeStmt(db: BetterSqlite3.Database, chunkSize: number): BetterSqlit | |
| return stmt; | ||
| } | ||
|
|
||
| function getEdgeStmt(db: BetterSqlite3.Database, chunkSize: number): BetterSqlite3.Statement { | ||
| function getEdgeStmt(db: BetterSqlite3Database, chunkSize: number): SqliteStatement { | ||
| let cache = edgeStmtCache.get(db); | ||
| if (!cache) { | ||
| cache = new Map(); | ||
|
|
@@ -254,7 +258,7 @@ function getEdgeStmt(db: BetterSqlite3.Database, chunkSize: number): BetterSqlit | |
| * Batch-insert node rows via multi-value INSERT statements. | ||
| * Each row: [name, kind, file, line, end_line, parent_id, qualified_name, scope, visibility] | ||
| */ | ||
| export function batchInsertNodes(db: BetterSqlite3.Database, rows: unknown[][]): void { | ||
| export function batchInsertNodes(db: BetterSqlite3Database, rows: unknown[][]): void { | ||
| if (!rows.length) return; | ||
| for (let i = 0; i < rows.length; i += BATCH_CHUNK) { | ||
| const end = Math.min(i + BATCH_CHUNK, rows.length); | ||
|
|
@@ -273,7 +277,7 @@ export function batchInsertNodes(db: BetterSqlite3.Database, rows: unknown[][]): | |
| * Batch-insert edge rows via multi-value INSERT statements. | ||
| * Each row: [source_id, target_id, kind, confidence, dynamic] | ||
| */ | ||
| export function batchInsertEdges(db: BetterSqlite3.Database, rows: unknown[][]): void { | ||
| export function batchInsertEdges(db: BetterSqlite3Database, rows: unknown[][]): void { | ||
| if (!rows.length) return; | ||
| for (let i = 0; i < rows.length; i += BATCH_CHUNK) { | ||
| const end = Math.min(i + BATCH_CHUNK, rows.length); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openReadonlyOrFailopenDbwas simplified tonew Database(dbPath) as unknown as LockedDatabase, butopenReadonlyOrFailstill uses the verbose three-linenew (Database as unknown as new (...) => BetterSqlite3Database)(...)form. Now that@types/better-sqlite3is a declared dev-dependency and properly typesDatabaseas a class constructor, the cast can be reduced to the same two-stepas unknown aspattern used elsewhere:Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Simplified
openReadonlyOrFailto use the samenew Database(...) as unknown as BetterSqlite3Databasepattern asopenDb. Commit: 9b469df.