Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
chore: add performance package with a project service hyperfine comparison#7870
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
JoshuaKGoldberg wants to merge5 commits intotypescript-eslint:mainfromJoshuaKGoldberg:performance-tooling
Uh oh!
There was an error while loading.Please reload this page.
Closed
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
e29c532
perf: add performance package with a project service hyperfine compar…
JoshuaKGoldberg2c28880
Merge branch 'main' into performance-tooling
JoshuaKGoldbergccfadf5
Added quick test-all table comparison
JoshuaKGoldberg31be1e6
Added allowDefaultProjectFallbackFilesGlobs
JoshuaKGoldberg2958c48
Remove console logs
JoshuaKGoldbergFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions.eslintignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions.github/workflows/performance.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: 'Performance Testing' | ||
on: workflow_dispatch | ||
jobs: | ||
comparison: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/prepare-install | ||
- run: brew install hyperfine | ||
- run: PERFORMANCE_FILE_COUNT=${{ matrix.file-count }} yarn workspace @typescript-eslint/performance run generate | ||
- run: hyperfine yarn workspace @typescript-eslint/performance run test:${{ matrix.test}} | ||
strategy: | ||
matrix: | ||
file-count: [50, 100, 150, 200] | ||
test: ['project', 'service'] | ||
summary: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/prepare-install | ||
- run: yarn workspace @typescript-eslint/performance run test:summary |
5 changes: 4 additions & 1 deletion.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletionspackages/performance/.eslintrc.cjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/strict-type-checked', | ||
'plugin:@typescript-eslint/stylistic-type-checked', | ||
], | ||
plugins: ['@typescript-eslint'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: true, | ||
tsconfigRootDir: __dirname, | ||
}, | ||
root: true, | ||
}; |
27 changes: 27 additions & 0 deletionspackages/performance/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Performance Testing | ||
A quick internal utility for testing lint performance. | ||
## Generating a Summary | ||
`test:summary` runs the three performance scenarios under different file counts, then prints a summary table: | ||
```shell | ||
yarn test:summary | ||
``` | ||
For each of those file counts, the generated code is 50% `.js` and 50% `.ts`. | ||
## Running Tests Manually | ||
First generate the number of files you'd like to test: | ||
```shell | ||
PERFORMANCE_FILE_COUNT=123 yarn generate | ||
``` | ||
Then run one or more of the test types: | ||
- `yarn test:project`: Traditional `project: true` | ||
- `yarn test:service` `EXPERIMENTAL_useProjectService` | ||
- `yarn test:service:seeded`: `EXPERIMENTAL_useProjectService`, with `allowDefaultProjectFallbackFilesGlobs` |
56 changes: 56 additions & 0 deletionspackages/performance/generate.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as fs from 'fs/promises'; | ||
import * as path from 'path'; | ||
import { | ||
generateESLintConfig, | ||
generateJsFile, | ||
generateTSConfig, | ||
generateTsFile, | ||
} from './generating.js'; | ||
import { directory, writeFile } from './writing.js'; | ||
const fileCount = Number(process.env.PERFORMANCE_FILE_COUNT); | ||
if (!fileCount) { | ||
throw new Error( | ||
`Invalid process.env.PERFORMANCE_FILE_COUNT: ${process.env.PERFORMANCE_FILE_COUNT}`, | ||
); | ||
} | ||
await fs.rm(directory, { force: true, recursive: true }); | ||
await fs.mkdir(path.join(directory, 'src'), { recursive: true }); | ||
// The root-level TSConfig is used for the project service, which intentionally | ||
// uses the default/inferred project for non-included JS files. | ||
await writeFile(`tsconfig.json`, generateTSConfig(false)); | ||
// The explicit project allows JS, akin to the common tsconfig.eslint.json. | ||
await writeFile(`tsconfig.project.json`, generateTSConfig(true)); | ||
for (const [alias, parserOptions] of [ | ||
['project', `project: "./tsconfig.project.json"`], | ||
['service', `EXPERIMENTAL_useProjectService: true`], | ||
[ | ||
'service.seeded', | ||
`allowDefaultProjectFallbackFilesGlobs: ["./src/*.js"],\n EXPERIMENTAL_useProjectService: true`, | ||
], | ||
] as const) { | ||
await writeFile( | ||
`.eslintrc.${alias}.cjs`, | ||
generateESLintConfig(parserOptions), | ||
); | ||
} | ||
for (let i = 0; i < fileCount; i += 1) { | ||
const [extension, generator] = | ||
i % 2 ? ['js', generateJsFile] : ['ts', generateTsFile]; | ||
await writeFile(`src/example${i}.${extension}`, generator(i)); | ||
} | ||
await writeFile( | ||
'src/index.ts', | ||
new Array(fileCount) | ||
.fill(undefined) | ||
.map((_, i) => `export { example${i} } from "./example${i}.js";`) | ||
.join('\n'), | ||
); |
48 changes: 48 additions & 0 deletionspackages/performance/generating.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export function generateESLintConfig(parserOptions: string) { | ||
return ` | ||
/* eslint-env node */ | ||
module.exports = { | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/strict-type-checked', | ||
'plugin:@typescript-eslint/stylistic-type-checked', | ||
], | ||
plugins: ['@typescript-eslint'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
${parserOptions}, | ||
tsconfigRootDir: __dirname | ||
}, | ||
root: true, | ||
}; | ||
`.trimStart(); | ||
} | ||
export function generateJsFile(i: number) { | ||
return ` | ||
export async function example${i}(input) { | ||
return typeof input === 'number' ? input.toPrecision(1) : input.toUpperCase(); | ||
} | ||
`.trimStart(); | ||
} | ||
export function generateTsFile(i: number) { | ||
return ` | ||
export async function example${i}<T extends number | string>(input: T) { | ||
return typeof input === 'number' ? input.toPrecision(1) : input.toUpperCase(); | ||
} | ||
`.trimStart(); | ||
} | ||
export function generateTSConfig(allowJs: boolean) { | ||
return ` | ||
{ | ||
"compilerOptions": { | ||
"allowJs": ${allowJs}, | ||
"module": "ESNext", | ||
"strict": true, | ||
"target": "ESNext" | ||
} | ||
} | ||
`.trimStart(); | ||
} |
28 changes: 28 additions & 0 deletionspackages/performance/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@typescript-eslint/performance", | ||
"version": "6.9.1", | ||
"private": true, | ||
"type": "module", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/typescript-eslint/typescript-eslint.git", | ||
"directory": "packages/performance" | ||
}, | ||
"scripts": { | ||
"generate": "tsx ./generate.ts", | ||
"generate:watch": "tsx --watch ./generate.ts", | ||
"test:project": "time eslint --config ./generated/.eslintrc.project.cjs ./generated || true", | ||
"test:service": "time eslint --config ./generated/.eslintrc.service.cjs ./generated || true", | ||
"test:service:seeded": "time eslint --config ./generated/.eslintrc.service.seeded.cjs ./generated || true", | ||
"test:summary": "tsx ./summary.ts" | ||
}, | ||
"dependencies": { | ||
"@typescript-eslint/eslint-plugin": "6.9.1", | ||
"@typescript-eslint/parser": "6.9.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "*", | ||
"execa": "*", | ||
"tsx": "*" | ||
} | ||
} |
17 changes: 17 additions & 0 deletionspackages/performance/summary.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { $ } from 'execa'; | ||
const getTiming = ({ stderr }: { stderr: string }) => | ||
stderr.trim().replace(/ +/g, ' '); | ||
const counts: Record<string, unknown> = {}; | ||
for (const fileCount of [5, 10, 25, 50, 75, 100, 125, 150, 175, 200]) { | ||
await $({ env: { PERFORMANCE_FILE_COUNT: `${fileCount}` } })`yarn generate`; | ||
const project = getTiming(await $`yarn test:project`); | ||
const service = getTiming(await $`yarn test:service`); | ||
const serviceSeeded = getTiming(await $`yarn test:service:seeded`); | ||
counts[fileCount] = { project, service, 'service (seeded)': serviceSeeded }; | ||
} | ||
console.table(counts); |
8 changes: 8 additions & 0 deletionspackages/performance/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"strict": true, | ||
"target": "ESNext" | ||
} | ||
} |
8 changes: 8 additions & 0 deletionspackages/performance/writing.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as fs from 'fs/promises'; | ||
import * as path from 'path'; | ||
export const directory = 'generated'; | ||
export async function writeFile(fileName: string, data: string) { | ||
await fs.writeFile(path.join(directory, fileName), data); | ||
} |
16 changes: 14 additions & 2 deletionspackages/typescript-estree/src/create-program/createProjectService.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletionpackages/typescript-estree/src/parseSettings/createParseSettings.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletionspackages/typescript-estree/src/parser-options.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletionspackages/typescript-estree/src/useProgramFromProjectService.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.