Skip to content
Draft
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
Empty file added attest.config.js
Empty file.
1,257 changes: 1,251 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
"type-check:test": "tsc --noEmit --project tsconfig.test.json",
"db:clean": "cd test/db && docker compose down --volumes",
"db:run": "cd test/db && docker compose up --detach && wait-for-localhost 3000",
"db:generate-test-types": "cd test/db && docker compose up --detach && wait-for-localhost 8080 && curl --location 'http://0.0.0.0:8080/generators/typescript?included_schemas=public,personal&detect_one_to_one_relationships=true' > ../types.generated.ts && node ../scripts/update-json-type.js && prettier --write ../types.generated.ts"
"db:generate-test-types": "cd test/db && docker compose up --detach && wait-for-localhost 8080 && curl --location 'http://0.0.0.0:8080/generators/typescript?included_schemas=public,personal&detect_one_to_one_relationships=true' > ../types.generated.ts && node ../scripts/update-json-type.js && prettier --write ../types.generated.ts",
"benchmark:types": "tsx test/types-benchmark/benchmarks.ts",
"benchmark:update-baselines": "node test/types-benchmark/update-baselines.js --update",
"benchmark:show-baselines": "node test/types-benchmark/update-baselines.js --show"
},
"dependencies": {
"@supabase/node-fetch": "^2.6.14"
Expand All @@ -66,6 +69,7 @@
"semantic-release-plugin-update-version-in-files": "^1.1.0",
"ts-jest": "^28.0.3",
"tstyche": "^4.3.0",
"tsx": "^4.20.5",
"type-fest": "^4.32.0",
"typedoc": "^0.22.16",
"typescript": "^4.5.5",
Expand Down
1 change: 1 addition & 0 deletions test/attest-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

47 changes: 47 additions & 0 deletions test/types-benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# PostgREST-js Type Inference Benchmarks

Type inference performance benchmarks using [@ark/attest](https://github.com/arktypeio/arktype/tree/main/ark/attest) based on the approach from [An approach to optimizing TypeScript type checking performance](https://www.geldata.com/blog/an-approach-to-optimizing-typescript-type-checking-performance).

## Quick Start

```bash
# Run benchmarks and see performance vs baseline
npm run benchmark:types

# Update baselines (like vitest --update)
npm run benchmark:update-baselines

# Show current baselines
npm run benchmark:show-baselines
```

## Files

- **`benchmarks.ts`** - Core PostgREST operations (select, update, insert, RPC)
- **`baselines.json`** - Current baseline values for all benchmarks
- **`update-baselines.js`** - Baseline management utility
- **`tsconfig.json`** - TypeScript configuration for benchmarks

## Understanding Results

- **📊 Delta: 0.00%** - Performance is stable (no change)
- **📈 Exceeded baseline by X%** - Performance degraded (more instantiations)
- **📉 Under baseline by X%** - Performance improved (fewer instantiations)

## Updating Baselines

When you make intentional changes that affect type inference performance:

```bash
npm run benchmark:update-baselines
```

This captures current performance as the new baseline, similar to `vitest --update` for snapshots.

## Current Baseline Values

- **Simple Select: Basic**: 1,935 instantiations
- **Simple Select: Single Column**: 3,044 instantiations
- **Simple Update: Basic**: 108 instantiations
- **Simple Insert: Basic**: 108 instantiations
- **Simple RPC: Basic**: 53 instantiations
7 changes: 7 additions & 0 deletions test/types-benchmark/baselines.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Simple Select: Basic": 1935,
"Simple Select: Single Column": 3044,
"Simple Update: Basic": 108,
"Simple Insert: Basic": 108,
"Simple RPC: Basic": 53
}
29 changes: 29 additions & 0 deletions test/types-benchmark/benchmarks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { bench } from '@ark/attest'
import { PostgrestClient } from '../../src/index'
import { Database } from '../types.generated'

// Create a mock client for type inference testing
const createMockClient = () => {
return new PostgrestClient<Database>('http://localhost:3000')
}

// Simple benchmarks that should work
bench('Simple Select: Basic', () => {
return createMockClient().from('users').select()
}).types([1935, 'instantiations'])

bench('Simple Select: Single Column', () => {
return createMockClient().from('users').select('username')
}).types([3044, 'instantiations'])

bench('Simple Update: Basic', () => {
return createMockClient().from('users').update({ status: 'ONLINE' })
}).types([108, 'instantiations'])

bench('Simple Insert: Basic', () => {
return createMockClient().from('users').insert({ username: 'testuser' })
}).types([108, 'instantiations'])

bench('Simple RPC: Basic', () => {
return createMockClient().rpc('get_status', { name_param: 'test' })
}).types([53, 'instantiations'])
Loading
Loading