How prisma/query-compiler-benchmarks works
Project Type and Purpose
• This project is a benchmarking suite focused on testing different configurations and variants of Prisma-based database interactions.
• It uses Node.js with TypeScript and leverages Docker Compose to manage external dependencies like the target database.
• The README shows that it’s designed for running benchmark tests (seeding data, executing tests, and reporting results) with options to generate JSON, CSV, and visual charts.
File Structure
• Top-level Elements:
• “main.ts”: Likely the main entry point that orchestrates benchmark tests.
• “docker-compose.yml”: Used to spin up external services, such as the database.
• “pnpm-workspace.yaml”, “package.json”, “tsconfig.json”: Indicating use of a TypeScript monorepo structure managed via pnpm.
• “.github/workflows”: Contains CI/CD pipeline configuration (e.g., automation of benchmarks).
• The “benches” Directory:
• Contains multiple subdirectories such as “prisma-common”, “prisma-native-qe”, “prisma-pg-napi-qe”, “prisma-pg-qc”, and “prisma-pg-wasm-qe”.
• Each subdirectory holds an “index.ts”, “setup.ts”, a “package.json”, and a "prisma" folder with its own “schema.prisma”. This pattern indicates that each module is an isolated benchmark targeting a different Prisma configuration or performance scenario.
• The “bin” Directory:
Gather Insights from the README
• The setup instructions (docker-compose up, pnpm install, environment variable configuration) emphasize initial environment setup including database connectivity.
• The customization instructions for reporting show that the outputs (in JSON) can be transformed and visualized—implying a two-stage process: execution of benchmarks followed by result processing and visualization.
Main Components
a. External Services:
• Docker-managed Database: Represent the database service started with docker-compose.
• CI/CD Pipeline: The GitHub workflows (bench.yml) to run tests/benchmarks automatically.
b. Application Execution:
• Main Runner: “main.ts” as the entry point that kicks off the benchmark tests.
• Benchmark Modules: The various subdirectories under “benches” (e.g., “prisma-common”, “prisma-native-qe”, etc.) which each execute a set of benchmark tests. They include their own Prisma schema and setup code, indicating self-contained test scenarios.
c. Utility and Reporting Tools:
• JSON to CSV conversion: “bin/json_to_csv”
d. Configuration and Environment:
• Environment configuration via “.envrc” (or manual set of DATABASE_URL) for database connectivity and custom reporting options.
• Configuration files (pnpm, tsconfig) suggesting a monorepo structure.
Relationships and Interactions
• The docker-compose setup spins up the external database service.
• “main.ts” (the application’s entry point) triggers the execution of the various benchmark modules.
• Each benchmark module connects to the database using the environment variable (DATABASE_URL) defined by .envrc.
• Benchmark modules generate results in JSON format.
• JSON outputs can be piped to “json_to_csv” for CSV conversion.
• The CI/CD pipeline (GitHub workflows) monitors and automates these tests to ensure consistent performance testing in integration.