Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions BOUNTY_TASK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Bounty Objective: TSPerf challenge submission: TypeLoad — real compiler-level type load-time analytics (MIT, installable VSIX)
Target: tsperf/tracer Issue #116
URL: https://github.com/tsperf/tracer/issues/116

## Issue Description
Submission for the TSPerf challenge (https://algora.io/challenges/tsperf).

Note: PRs/issues on algora-io/algora are restricted to prior contributors (tried: PR branch AmirDiaz/algora@tsperf-typeload-submission + issue, both blocked), so submitting here at the challenge-referenced repo.

**Links**
- Source (MIT): https://github.com/AmirDiaz/typeload
- Installable VSIX release: https://github.com/AmirDiaz/typeload/releases/tag/v0.1.0 (asset: typeload-0.1.0.vsix)

**What it does**
A VS Code extension that shows the complexity / time to load of a type in TypeScript, measured inside the compiler:
- **First-touch time (ms)** per declaration — the wall-clock cost of the first `getTypeAtLocation` on the declaration in a fresh program (the cost you pay on file open / build cold-start).
- **Checker instantiations** and **types created** per declaration — read from the TS 5.x checker counters (`getInstantiationCount`, `getTypeCount`), the same instrumentation technique as `@definitelytyped/perf`.
- Surfaces the numbers as **CodeLens** above each declaration (`⚡ 6.8 ms · 161 inst · 130 types`), a **slowest-types leaderboard** webview with per-file aggregates and click-to-jump, and an **isolated cursor re-measurement** command.
- Each run spawns a **fresh worker process** and resolves the **project's own TypeScript** from its node_modules (bundled fallback), so results are version-accurate and comparable across runs.

**Why different from prior entries**: existing entries time language-service responses (editor overhead included) or score complexity from the rendered type string (ignores caching, laziness, aliasing). TypeLoad reads the compiler's real counters around each declaration's first resolution.

**Verification**: `npm run compile` clean; `npm test` 6/6 headless engine + worker CLI tests; packaged with `vsce package` (4.3 MB VSIX attached to the release).

Relates to the tracer README help-wanted items: extended diagnostics from compiler/tsserver APIs, and better data display (CodeLens + leaderboard).

Happy to iterate — including a `tsc --generateTrace` cross-check view — if maintainers want more before considering it a successful solution.

## Instructions for Kuro (Autonomous Solver):
1. Use skills: `systematic-debugging` and `code-review-and-quality`.
2. Inspect the repository structure, locate relevant files, and understand the bug/feature.
3. Apply the minimal, robust fix or implementation.
4. Run any existing test suites or linters in the workspace.
5. Ensure the fix adheres to the project's existing code style.
6. When done, output a summary of files modified and verification results.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@

To avoid the overhead of launching a separate tsserver, it currently queries the VSCode language server to get information about tokens in an open file, and uses the timings of the responses as a proxy for the complexity of the types, following the pattern of [`@definitelytyped/perf`](https://github.com/microsoft/DefinitelyTyped-tools/blob/41ba894ba571e55fa91ef0bb0d44d6eb6d201943/packages/perf).

## Compiler type load metrics (TypeLoad)

Set `tsperf.tracer.enableTypeLoad` and run `Tracer: Measure type load` to measure how long the TypeScript compiler takes to resolve each declaration for the first time in a fresh program - the cost paid on file open or on a cold build.

For every top-level declaration the measurement reports:

- **First-touch time (ms)** - wall clock time of the first `getTypeAtLocation` call for the declaration.
- **Checker instantiations** and **types created** - the deltas of the `getInstantiationCount` / `getTypeCount` counters around that call, the same instrumentation technique used by [`@definitelytyped/perf`](https://github.com/microsoft/DefinitelyTyped-tools/blob/41ba894ba571e55fa91ef0bb0d44d6eb6d201943/packages/perf).

Results are shown as CodeLens above each declaration (`⚡ 6.8 ms · 161 inst · 130 types`). `Tracer: Show slowest types` opens a leaderboard with per-file aggregates that jumps to a declaration when clicked, and `Tracer: Measure type load at cursor` re-measures a single declaration in a fresh program for an isolated number.

Measurements run inside the extension host against the project's own TypeScript (see `tsperf.tracer.typescriptPathMode`) so they are version accurate and comparable across runs. The measuring engine (`src/typeLoadEngine.ts`) is free of `vscode` imports and is covered by `test/typeLoadEngine.test.ts`.

## Trace file view and metrics

The `Tracer: tsc trace` command can be run to gather accurate timings. As with real-time metrics, these create diagnostics in the editor open files. It also opens an interface to browse trace files. Editor and UI commands enable navigating between locations in the editor and the trace.
Expand Down
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,24 @@
},
"description": "todo",
"order": 15
},
"tsperf.tracer.enableTypeLoad": {
"type": "boolean",
"default": false,
"description": "Measure type load from the TypeScript compiler and show it as CodeLens",
"order": 16
},
"tsperf.tracer.typeLoadWarmupPasses": {
"type": "number",
"default": 0,
"description": "Throw-away measurement passes run before the reported type load numbers",
"order": 17
},
"tsperf.tracer.typeLoadLeaderboardSize": {
"type": "number",
"default": 25,
"description": "Number of slowest declarations shown in the type load leaderboard",
"order": 18
}
}
},
Expand Down Expand Up @@ -322,6 +340,21 @@
"title": "Open trace directory in file browser",
"command": "tsperf.tracer.openTraceDirExternal",
"category": "Tracer"
},
{
"title": "Measure type load",
"command": "tsperf.tracer.measureTypeLoad",
"category": "Tracer"
},
{
"title": "Measure type load at cursor",
"command": "tsperf.tracer.measureTypeLoadAtCursor",
"category": "Tracer"
},
{
"title": "Show slowest types",
"command": "tsperf.tracer.showTypeLoadLeaderboard",
"category": "Tracer"
}
],
"menus": {
Expand Down
9 changes: 9 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const currentConfig = {
enableTraceMetrics: true,
enableRealtimeMetrics: true,
fileBrowserExecutable: '',
enableTypeLoad: false,
typeLoadWarmupPasses: 0,
typeLoadLeaderboardSize: 25,
} satisfies Record<ConfigKey, any>

export function getCurrentConfig() {
Expand Down Expand Up @@ -67,6 +70,9 @@ const configValidate = {
enableTraceMetrics: isBoolean,
enableRealtimeMetrics: isBoolean,
fileBrowserExecutable: isString,
enableTypeLoad: isBoolean,
typeLoadWarmupPasses: isNumber,
typeLoadLeaderboardSize: isNumber,
} satisfies Record<ConfigKey, any>

function noop() {
Expand All @@ -89,6 +95,9 @@ const configHandlers = {
enableTraceMetrics: noop,
enableRealtimeMetrics: noop,
fileBrowserExecutable: noop,
enableTypeLoad: noop,
typeLoadWarmupPasses: noop,
typeLoadLeaderboardSize: noop,
} satisfies Record<ConfigKey, any>

let configuration = vscode.workspace.getConfiguration(extPrefix)
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const configKeys = [
'enableTraceMetrics',
'enableRealtimeMetrics',
'fileBrowserExecutable',
'enableTypeLoad',
'typeLoadWarmupPasses',
'typeLoadLeaderboardSize',
] as const

export type ConfigKey = typeof configKeys[number]
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { initDiagnostics } from './traceDiagnostics'
import { initWebviewPanel } from './webview'
import { initStatusBar } from './statusBar'
import { initAppState } from './appState'
import { initTypeLoad } from './typeLoad'

let ts: typeof import('typescript')
let tsPath: string
Expand Down Expand Up @@ -60,6 +61,7 @@ export async function activate(context: vscode.ExtensionContext) {
registerCommands(context)
initStatusBar(context)
initDiagnostics(context)
initTypeLoad(context)
}

export function deactivate() {}
Expand Down
Loading
Loading