From 00158128f525ce95e16dfe3ca4cc5b0e29c1fdbe Mon Sep 17 00:00:00 2001 From: Kyle Scott Date: Mon, 13 Nov 2023 19:02:08 -0500 Subject: [PATCH] fix bench script --- .github/workflows/bench.yml | 2 +- benchmarks/package.json | 2 +- benchmarks/src/bench.ts | 40 ------------------------------------- benchmarks/src/subgraph.ts | 32 ++++++++++++++++++++++++++++- benchmarks/tsup.config.ts | 2 +- package.json | 4 ++-- 6 files changed, 36 insertions(+), 46 deletions(-) delete mode 100644 benchmarks/src/bench.ts diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 595007fcd..2fedab0cf 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -61,7 +61,7 @@ jobs: uses: ./.github/actions/setup - name: Bench - run: pnpm bench:ponder-ci + run: pnpm bench:ponder:ci env: ANVIL_FORK_URL: ${{ secrets.ANVIL_FORK_URL }} DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres diff --git a/benchmarks/package.json b/benchmarks/package.json index c36c8d8b0..3d48461a7 100644 --- a/benchmarks/package.json +++ b/benchmarks/package.json @@ -3,7 +3,7 @@ "private": true, "scripts": { "bench:ponder": "export $(grep -v '^#' .env.local | xargs) && rm -rf data/ && docker-compose up --detach && tsup-node && (node dist/ponder.mjs || true) && docker-compose down", - "bench:ponder-ci": "tsup-node && node dist/ponder.mjs" + "bench:ponder:ci": "tsup-node && node dist/ponder.mjs" }, "devDependencies": { "@graphprotocol/graph-cli": "0.54.0-alpha-20230727052453-1e0e6e5", diff --git a/benchmarks/src/bench.ts b/benchmarks/src/bench.ts deleted file mode 100644 index 425387cb4..000000000 --- a/benchmarks/src/bench.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { readFileSync, rmSync, writeFileSync } from "node:fs"; - -import { subgraph } from "./subgraph"; - -const changeMappingFileDelim = (delim: string) => { - let mappingFileContents = readFileSync("./subgraph/src/mapping.ts", { - encoding: "utf-8", - }); - mappingFileContents = mappingFileContents.replace( - /(kevin:.)/g, - `kevin:${delim}`, - ); - - writeFileSync("./subgraph/src/mapping.ts", mappingFileContents, "utf-8"); -}; - -const bench = async () => { - // Reset handler delimeter - changeMappingFileDelim("-"); - - // Clear cached files - rmSync("./ponder/.ponder/", { - recursive: true, - force: true, - }); - rmSync("./ponder/generated/", { - recursive: true, - force: true, - }); - - const subgraphCold = await subgraph(); - console.log({ subgraphCold }); - - // Force handler cache invalidation - changeMappingFileDelim("+"); - - // const subgraphHot = await subgraph(); -}; - -await bench(); diff --git a/benchmarks/src/subgraph.ts b/benchmarks/src/subgraph.ts index 3acec7f31..022cf6358 100644 --- a/benchmarks/src/subgraph.ts +++ b/benchmarks/src/subgraph.ts @@ -1,3 +1,5 @@ +import { readFileSync, writeFileSync } from "node:fs"; + import { execa } from "execa"; import parsePrometheusTextFormat from "parse-prometheus-text-format"; @@ -104,7 +106,7 @@ const waitForSyncComplete = async () => { return duration; }; -export const subgraph = async () => { +const subgraph = async () => { console.log(`Waiting for Graph Node to be ready...`); const setupDuration = await waitForGraphNode(); @@ -140,3 +142,31 @@ export const subgraph = async () => { return { setupDuration, duration }; }; + +const changeMappingFileDelim = (delim: string) => { + let mappingFileContents = readFileSync("./subgraph/src/mapping.ts", { + encoding: "utf-8", + }); + mappingFileContents = mappingFileContents.replace( + /(kevin:.)/g, + `kevin:${delim}`, + ); + + writeFileSync("./subgraph/src/mapping.ts", mappingFileContents, "utf-8"); +}; + +const bench = async () => { + // Reset handler delimeter + changeMappingFileDelim("-"); + + const subgraphCold = await subgraph(); + + // Force handler cache invalidation + changeMappingFileDelim("+"); + + const subgraphHot = await subgraph(); + + console.log({ subgraphCold, subgraphHot }); +}; + +await bench(); diff --git a/benchmarks/tsup.config.ts b/benchmarks/tsup.config.ts index 3164a41ec..c80e53ad9 100644 --- a/benchmarks/tsup.config.ts +++ b/benchmarks/tsup.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from "tsup"; export default defineConfig({ - entry: ["src/ponder.ts"], + entry: ["src/ponder.ts", "src/subgraph.ts"], bundle: true, format: ["esm"], sourcemap: false, diff --git a/package.json b/package.json index 9d7502983..6eb0f3cce 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "private": true, "scripts": { - "bench": "pnpm --filter \"./benchmarks\" bench", - "bench:ci": "pnpm --filter \"./benchmarks\" bench:ci", + "bench:ponder": "pnpm --filter \"./benchmarks\" bench:ponder", + "bench:ponder:ci:": "pnpm --filter \"./benchmarks\" bench:ponder:ci", "build": "pnpm --filter \"@ponder/core\" build && pnpm --filter \"./packages/*\" --filter \"!@ponder/core\" --parallel build", "changeset:release": "pnpm build && changeset publish", "changeset:version": "changeset version && pnpm install --lockfile-only",