Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/quick-skill-reads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/intent': patch
---

Reduce repeated filesystem reads and path calculations in list, load, validate, and stale commands. Reuse command-scoped manifests, skill discovery, and shared workspace artifacts; index artifact matches once per package and batch workspace identity checks.
14 changes: 6 additions & 8 deletions benchmarks/intent/list.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rmSync } from 'node:fs'
import { join } from 'node:path'
import { afterAll, beforeAll, bench, describe } from 'vitest'
import { afterAll, beforeAll, describe, test } from 'vitest'
import {
createBenchOptions,
createCliRunner,
Expand All @@ -9,7 +9,7 @@ import {
writeFile,
writeJson,
writePackage,
} from './helpers.js'
} from './helpers.ts'

type ListFixture = {
globalNodeModules: string
Expand Down Expand Up @@ -148,14 +148,12 @@ describe('intent list', () => {
beforeAll(setup)
afterAll(teardown)

bench(
'scans a consumer workspace',
async () => {
test('scans a consumer workspace', { timeout: 30_000 }, async ({ bench }) => {
await bench('scans a consumer workspace', async () => {
const state = getFixture()
for (let index = 0; index < 3; index++) {
await state.runner.run(['list', '--json'])
}
},
createBenchOptions(setup, teardown),
)
}).run(createBenchOptions(setup, teardown))
})
})
63 changes: 38 additions & 25 deletions benchmarks/intent/load.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rmSync } from 'node:fs'
import { join } from 'node:path'
import { afterAll, beforeAll, bench, describe } from 'vitest'
import { afterAll, beforeAll, describe, test } from 'vitest'
import {
createBenchOptions,
createCliRunner,
Expand All @@ -9,7 +9,7 @@ import {
writeFile,
writeJson,
writePackage,
} from './helpers.js'
} from './helpers.ts'

type LoadFixture = {
root: string
Expand Down Expand Up @@ -171,38 +171,51 @@ describe('intent load', () => {
beforeAll(setup)
afterAll(teardown)

bench(
test(
'loads a direct dependency skill',
async () => {
const state = getFixture()
for (let index = 0; index < 10; index++) {
await state.runner.run(['load', '@bench/query#query/cache', '--path'])
}
{ timeout: 30_000 },
async ({ bench }) => {
await bench('loads a direct dependency skill', async () => {
const state = getFixture()
for (let index = 0; index < 10; index++) {
await state.runner.run(['load', '@bench/query#query/cache', '--path'])
}
}).run(createBenchOptions(setup, teardown))
},
createBenchOptions(setup, teardown),
)

bench(
test(
'loads direct dependency content as json',
async () => {
const state = getFixture()
for (let index = 0; index < 10; index++) {
await state.runner.run(['load', '@bench/query#query/cache', '--json'])
}
{ timeout: 30_000 },
async ({ bench }) => {
await bench('loads direct dependency content as json', async () => {
const state = getFixture()
for (let index = 0; index < 10; index++) {
await state.runner.run(['load', '@bench/query#query/cache', '--json'])
}
}).run(createBenchOptions(setup, teardown))
},
createBenchOptions(setup, teardown),
)

bench(
test(
'loads a direct dependency from a large workspace',
async () => {
const state = getFixture()
await runInCwd(state.workspaceRoot, async () => {
for (let index = 0; index < 10; index++) {
await state.runner.run(['load', '@bench/query#query/cache', '--path'])
}
})
{ timeout: 30_000 },
async ({ bench }) => {
await bench(
'loads a direct dependency from a large workspace',
async () => {
const state = getFixture()
await runInCwd(state.workspaceRoot, async () => {
for (let index = 0; index < 10; index++) {
await state.runner.run([
'load',
'@bench/query#query/cache',
'--path',
])
}
})
},
).run(createBenchOptions(setup, teardown))
},
createBenchOptions(setup, teardown),
)
})
44 changes: 37 additions & 7 deletions benchmarks/intent/stale.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rmSync } from 'node:fs'
import { readFileSync, rmSync } from 'node:fs'
import { join } from 'node:path'
import { afterAll, beforeAll, bench, describe } from 'vitest'
import { afterAll, beforeAll, describe, test } from 'vitest'
import {
createBenchOptions,
createCliRunner,
Expand All @@ -9,7 +9,7 @@ import {
writeFile,
writeJson,
writeSkill,
} from './helpers.js'
} from './helpers.ts'

type StaleFixture = {
root: string
Expand Down Expand Up @@ -125,6 +125,25 @@ async function setup(): Promise<void> {
await getFixture().runner.setup()
}

async function setupWithArtifacts(): Promise<void> {
await setup()
const { root } = getFixture()
const skills = ['alpha', 'beta', 'gamma', 'delta'].flatMap((name) => {
const state = JSON.parse(
readFileSync(
join(root, 'packages', name, 'skills', 'sync-state.json'),
'utf8',
),
) as { skills: Record<string, unknown> }
return Object.keys(state.skills).map((skill) => ({
package: `packages/${name}`,
slug: skill,
path: `packages/${name}/skills/${skill}/SKILL.md`,
}))
})
writeJson(join(root, '_artifacts', 'skill_tree.yaml'), { skills })
}

function teardown(): void {
if (fixture) {
fixture.runner.teardown()
Expand All @@ -139,14 +158,25 @@ describe('intent stale', () => {
beforeAll(setup)
afterAll(teardown)

bench(
'reports workspace drift',
async () => {
test('reports workspace drift', { timeout: 30_000 }, async ({ bench }) => {
await bench('reports workspace drift', async () => {
const state = getFixture()
for (let index = 0; index < 3; index++) {
await state.runner.run(['stale', '--json'])
}
}).run(createBenchOptions(setup, teardown))
})

test(
'reports workspace drift with shared artifacts',
{ timeout: 30_000 },
async ({ bench }) => {
await bench('reports workspace drift with shared artifacts', async () => {
const state = getFixture()
for (let index = 0; index < 3; index++) {
await state.runner.run(['stale', '--json'])
}
}).run(createBenchOptions(setupWithArtifacts, teardown))
},
createBenchOptions(setup, teardown),
)
})
22 changes: 11 additions & 11 deletions benchmarks/intent/startup.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawnSync } from 'node:child_process'
import { fileURLToPath } from 'node:url'
import { bench, describe } from 'vitest'
import { describe, test } from 'vitest'

const cliPath = fileURLToPath(
new URL('../../packages/intent/dist/cli.mjs', import.meta.url),
Expand All @@ -24,19 +24,19 @@ function runNode(args: Array<string>): void {
}

describe('cold start', () => {
bench(
test(
'empty node process (baseline)',
() => {
runNode(['-e', ''])
{ timeout: 30_000 },
async ({ bench }) => {
await bench('empty node process (baseline)', () => {
runNode(['-e', ''])
}).run(coldStartBenchOptions)
},
coldStartBenchOptions,
)

bench(
'intent --help',
() => {
test('intent --help', { timeout: 30_000 }, async ({ bench }) => {
await bench('intent --help', () => {
runNode([cliPath, '--help'])
},
coldStartBenchOptions,
)
}).run(coldStartBenchOptions)
})
})
3 changes: 2 additions & 1 deletion benchmarks/intent/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
"noEmit": true,
"allowImportingTsExtensions": true
},
"include": ["*.ts"]
}
20 changes: 11 additions & 9 deletions benchmarks/intent/validate.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rmSync } from 'node:fs'
import { join } from 'node:path'
import { afterAll, beforeAll, bench, describe } from 'vitest'
import { afterAll, beforeAll, describe, test } from 'vitest'
import {
createBenchOptions,
createCliRunner,
Expand All @@ -9,7 +9,7 @@ import {
writeFile,
writeJson,
writeSkill,
} from './helpers.js'
} from './helpers.ts'

type ValidateFixture = {
root: string
Expand Down Expand Up @@ -120,14 +120,16 @@ describe('intent validate', () => {
beforeAll(setup)
afterAll(teardown)

bench(
test(
'checks a shipped skills tree',
async () => {
const state = getFixture()
for (let index = 0; index < 3; index++) {
await state.runner.run(['validate'])
}
{ timeout: 30_000 },
async ({ bench }) => {
await bench('checks a shipped skills tree', async () => {
const state = getFixture()
for (let index = 0; index < 3; index++) {
await state.runner.run(['validate'])
}
}).run(createBenchOptions(setup, teardown))
},
createBenchOptions(setup, teardown),
)
})
2 changes: 2 additions & 0 deletions benchmarks/intent/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ export default defineConfig({
name: '@benchmarks/intent',
watch: false,
environment: 'node',
// Measure the built CLI without module-export getter wrappers.
experimental: { viteModuleRunner: false },
},
})
6 changes: 4 additions & 2 deletions packages/intent/src/commands/stale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
isSkillExcluded,
} from '../core/excludes.js'
import { resolveProjectContext } from '../core/project-context.js'
import { createIntentFsCache } from '../discovery/fs-cache.js'
import {
isSourcePermitted,
readSkillSourcesConfig,
Expand Down Expand Up @@ -135,9 +136,10 @@ function filterStaleReportSkills(
): Array<StalenessReport> {
const cwd = resolve(process.cwd(), targetDir ?? process.cwd())
const context = resolveProjectContext({ cwd })
const config = readSkillSourcesConfig(cwd, context)
const fsCache = createIntentFsCache()
const config = readSkillSourcesConfig(cwd, context, fsCache)
const excludeMatchers = compileExcludePatterns(
getEffectiveExcludePatterns({}, context),
getEffectiveExcludePatterns({}, context, fsCache),
)

return reports.map((report) => ({
Expand Down
Loading
Loading