From 412338c71726e96e3deb76b4aac99a322a91f556 Mon Sep 17 00:00:00 2001 From: Esben Sparre Andreasen Date: Thu, 14 Nov 2024 16:29:31 +0100 Subject: [PATCH] feat: parallel log scanning --- .../compare-performance-view.ts | 24 ++++++++++++++----- .../ql-vscode/src/log-insights/log-scanner.ts | 14 ++++++++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/extensions/ql-vscode/src/compare-performance/compare-performance-view.ts b/extensions/ql-vscode/src/compare-performance/compare-performance-view.ts index 28925ba1a..aae1621b0 100644 --- a/extensions/ql-vscode/src/compare-performance/compare-performance-view.ts +++ b/extensions/ql-vscode/src/compare-performance/compare-performance-view.ts @@ -1,3 +1,4 @@ +import { statSync } from "fs"; import { ViewColumn } from "vscode"; import type { App } from "../common/app"; @@ -11,6 +12,7 @@ import { showAndLogExceptionWithTelemetry } from "../common/logging"; import { extLogger } from "../common/logging/vscode"; import type { WebviewPanelConfig } from "../common/vscode/abstract-webview"; import { AbstractWebview } from "../common/vscode/abstract-webview"; +import { withProgress } from "../common/vscode/progress"; import { telemetryListener } from "../common/vscode/telemetry"; import type { HistoryItemLabelProvider } from "../query-history/history-item-label-provider"; import { PerformanceOverviewScanner } from "../log-insights/performance-comparison"; @@ -41,12 +43,22 @@ export class ComparePerformanceView extends AbstractWebview< await this.waitForPanelLoaded(); - // TODO: try processing in (async) parallel once readJsonl is streaming - const fromPerf = await scanLog( - fromJsonLog, - new PerformanceOverviewScanner(), - ); - const toPerf = await scanLog(toJsonLog, new PerformanceOverviewScanner()); + function scanLogWithProgress(log: string, logDescription: string) { + const bytes = statSync(log).size; + return withProgress( + async (progress) => + scanLog(log, new PerformanceOverviewScanner(), progress), + + { + title: `Scanning evaluator log ${logDescription} (${(bytes / 1024 / 1024).toFixed(1)} MB)`, + }, + ); + } + + const [fromPerf, toPerf] = await Promise.all([ + scanLogWithProgress(fromJsonLog, "1/2"), + scanLogWithProgress(toJsonLog, "2/2"), + ]); await this.postMessage({ t: "setPerformanceComparison", diff --git a/extensions/ql-vscode/src/log-insights/log-scanner.ts b/extensions/ql-vscode/src/log-insights/log-scanner.ts index 9324a5994..55b655c25 100644 --- a/extensions/ql-vscode/src/log-insights/log-scanner.ts +++ b/extensions/ql-vscode/src/log-insights/log-scanner.ts @@ -1,6 +1,7 @@ -import type { SummaryEvent } from "./log-summary"; -import { readJsonlFile } from "../common/jsonl-reader"; import type { Disposable } from "../common/disposable-object"; +import { readJsonlFile } from "../common/jsonl-reader"; +import type { ProgressCallback } from "../common/vscode/progress"; +import type { SummaryEvent } from "./log-summary"; /** * Callback interface used to report diagnostics from a log scanner. @@ -114,7 +115,7 @@ export class EvaluationLogScannerSet { } /** - * Scan the evaluator summary log using the given scanner. For conveience, returns the scanner. + * Scan the evaluator summary log using the given scanner. For convenience, returns the scanner. * * @param jsonSummaryLocation The file path of the JSON summary log. * @param scanner The scanner to process events from the log @@ -122,7 +123,14 @@ export class EvaluationLogScannerSet { export async function scanLog( jsonSummaryLocation: string, scanner: T, + progress?: ProgressCallback, ): Promise { + progress?.({ + // XXX all scans have step 1 - the backing progress tracker allows increments instead of steps - but for now we are happy with a tiny UI that says what is happening + message: `Scanning ...`, + step: 1, + maxStep: 2, + }); await readJsonlFile(jsonSummaryLocation, async (obj) => { scanner.onEvent(obj); });