Back to Prisma

Task: Review and Refine Query Performance Benchmarks

docs/plans/benchmark-improvements/003-review-query-performance-benchmarks.md

7.9.0-dev.45.0 KB
Original Source

Task: Review and Refine Query Performance Benchmarks

Overview

Review the newly implemented query performance benchmarks in packages/client/src/__tests__/benchmarks/query-performance/ to ensure comprehensive coverage, accuracy, and alignment with real-world Prisma usage patterns.

Current State

The query performance benchmark suite has been implemented with:

  • query-performance.bench.ts - End-to-end benchmarks with SQLite/better-sqlite3
  • compilation.bench.ts - Wasm query compiler benchmarks
  • schema.prisma - Comprehensive schema with typical web app models
  • seed-data.ts - Configurable data generation (small/medium/large)
  • prisma.config.ts - Prisma configuration for benchmarks

Review Areas

1. Query Coverage Completeness

Verify all critical query patterns are covered:

CategoryCurrent CoverageReview Items
Read Operations✅ findUnique, findFirst, findManyCheck edge cases
Filtering✅ Simple, OR, complex, containsAdd NOT, IN, nested filters
Relations✅ 1:1, 1:N, nested includesAdd select with relations
Pagination✅ skip/takeAdd cursor-based pagination
Ordering✅ Single fieldAdd multi-field orderBy
Aggregations✅ count, aggregate, groupByAdd _count on relations
Writes✅ create, update, updateManyAdd createMany, delete, deleteMany
Transactions✅ Sequential, batchAdd interactive transactions
Raw queries❌ MissingAdd $queryRaw, $executeRaw

2. Schema Alignment

Review schema.prisma for:

  • Model complexity matches typical production schemas
  • Index coverage is realistic
  • Relation patterns cover common use cases (1:1, 1:N, M:N)
  • Field types include common variations (String, Int, Float, Boolean, DateTime)
  • Self-referential relations are tested (Category hierarchy, Comment replies)

3. Data Seeding Review

Review seed-data.ts configurations:

ConfigUsersPosts/UserComments/PostReview
small1053Good for quick iteration
medium100105Standard benchmark run
large5002010Stress testing

Questions to address:

  • Are data volumes representative of production workloads?
  • Is the randomization providing sufficient variety?
  • Should we add an "xlarge" config for stress testing?

4. Compilation Benchmarks

Review compilation.bench.ts for:

  • All query types have corresponding compilation benchmarks
  • BENCHMARK_DATAMODEL matches the runtime schema
  • Query objects accurately represent internal protocol format
  • Compiler instantiation is measured separately

5. Benchmark Accuracy

Verify benchmark measurements are accurate:

  • Setup/teardown doesn't pollute measurements
  • Warm-up runs are handled by the framework
  • Database state is consistent between iterations
  • Memory pressure doesn't affect results (SQLite in-memory)

Action Items

High Priority

  1. Add missing query patterns:

    • createMany operations
    • delete and deleteMany operations
    • Cursor-based pagination
    • Raw query benchmarks ($queryRaw, $executeRaw)
  2. Add edge case benchmarks:

    • Empty result sets
    • Single vs. batch operations comparison
    • Large payload writes

Medium Priority

  1. Enhance filtering benchmarks:

    • NOT conditions
    • in operator with various array sizes
    • Deeply nested where clauses
    • Date range filtering
  2. Add missing relation patterns:

    • select with nested relations (not just include)
    • M:N relation queries through junction table
    • Relation counts without loading data

Low Priority

  1. Consider additional scenarios:
    • Multiple concurrent queries
    • Connection pool behavior (not applicable to SQLite in-memory)
    • Query plan caching effects

Validation Steps

After refinements:

bash
# Run all query performance benchmarks
pnpm bench query-performance

# Run compilation benchmarks
pnpm bench compilation

# Verify no regressions with full suite
pnpm bench

Output Expectations

After review and refinements:

  • All benchmark categories should have 15-30 individual benchmarks
  • Execution time for full suite should be < 5 minutes locally
  • Results should be stable (±5% variance between runs)
  • CI should pass without timeouts

Dependencies

  • None (can be done independently)
  • Task 001: Migrate to tinybench (API changes may simplify async handling)
  • Task 002: Bump codspeed version (ensure compatibility)