Skip to content

Commit

Permalink
ci: Type check perf (#3406)
Browse files Browse the repository at this point in the history
* chore: add scripts to monitor type check performance

* chore: add jobs for type-check-perf-monitoring

* chore: rm a comment

* refactor: mv type-check-perf perf-measures/type-check

* rm .eslintrc.cjs

* chore: ignore *result.txt
  • Loading branch information
m-shaka authored Sep 22, 2024
1 parent dfbd717 commit 66df4e1
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,54 @@ jobs:
with:
name: coverage-lambda-edge
path: coverage/

perf-measures-type-check-on-pr:
runs-on: ubuntu-latest
permissions:
contents: 'read'
pull-requests: 'write'
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- uses: actions/cache/restore@v4
with:
path: perf-measures/type-check/previous-result.txt
restore-keys: |
type-check-perf-previous-result-
key: type-check-perf-previous-result-
- run: bun scripts/generate-app.ts
working-directory: perf-measures/type-check
- run: bun tsc -p tsconfig.build.json --diagnostics > result.txt
working-directory: perf-measures/type-check
- run: |
{
echo 'COMPARISON<<EOF'
bun scripts/process-results.ts
echo 'EOF'
} >> "$GITHUB_ENV"
working-directory: perf-measures/type-check
- run: echo "$COMPARISON"
# remove the comment out after we make sure that caching is working
# - uses: thollander/actions-comment-pull-request@v2
# with:
# comment_tag: perf-measures/type-check
# message: ${{ env.COMPARISON }}


perf-measures-type-check-on-main:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun scripts/generate-app.ts
working-directory: perf-measures/type-check
- run: bun tsc -p tsconfig.build.json --diagnostics > previous-result.txt
working-directory: perf-measures/type-check
- uses: actions/cache/save@v4
with:
path: perf-measures/type-check/previous-result.txt
key: type-check-perf-previous-result-${{ github.sha }}
13 changes: 13 additions & 0 deletions perf-measures/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"noEmit": true,
"rootDir": "..",
"strict": true
},
"include": [
"**/*.ts",
"**/*.tsx"
]
}
4 changes: 4 additions & 0 deletions perf-measures/type-check/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
generated
!generated/.gitkeep
trace
*result.txt
4 changes: 4 additions & 0 deletions perf-measures/type-check/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { app } from './generated/app'
import { hc } from '../../src/client'

const client = hc<typeof app>('/')
Empty file.
25 changes: 25 additions & 0 deletions perf-measures/type-check/scripts/generate-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { writeFile } from 'node:fs'
import * as path from 'node:path'

const count = 200

const generateRoutes = (count: number) => {
let routes = `import { Hono } from '../../../src'
export const app = new Hono()`
for (let i = 1; i <= count; i++) {
routes += `
.get('/route${i}/:id', (c) => {
return c.json({
ok: true
})
})`
}
return routes
}

const routes = generateRoutes(count)

writeFile(path.join(import.meta.dirname, '../generated/app.ts'), routes, (err) => {
if (err) { throw err }
console.log(`${count} routes have been written to app.ts`)
})
18 changes: 18 additions & 0 deletions perf-measures/type-check/scripts/process-results.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as fs from 'node:fs/promises'

async function main() {
const currentResult = (await fs.readFile('./result.txt')).toString().split('\n')
const previousResult = await fs.readFile('./previous-result.txt')
.then((data) => data.toString().split('\n'))
.catch(() => null)
const table = ['|| Current | Previous |', '|---|---|---|']
for (const [i, line] of currentResult.entries()) {
if (line === '') {continue}
const [name, value] = line.split(':')
const mainValue = previousResult?.[i]?.split(':')?.[1]
table.push(`| ${name?.trim()} | ${value?.trim()} | ${mainValue ? mainValue.trim() : 'N/A'} |`)
}
console.log(table.join('\n'))
}

main()
4 changes: 4 additions & 0 deletions perf-measures/type-check/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["client.ts"]
}
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default defineConfig({
'runtime-tests',
'build.ts',
'src/test-utils',
'perf-measures',

// types are compile-time only, so their coverage cannot be measured
'src/**/types.ts',
Expand Down

0 comments on commit 66df4e1

Please sign in to comment.