@@ -6,16 +6,25 @@ import { git, localRepoPath, makeTmpDir, npm } from '../utils.js';
66import { LOCAL } from './config.js' ;
77import type { BenchmarkProject } from './types.js' ;
88
9- // Build a benchmark-friendly environment for each revision.
9+ // Build a benchmark-friendly install for each revision.
1010export function prepareBenchmarkProjects (
1111 revisionList : ReadonlyArray < string > ,
1212) : Array < BenchmarkProject > {
1313 const { tmpDirPath } = makeTmpDir ( 'graphql-js-benchmark' ) ;
14+ const { tmpDirPath : benchmarkCachePath } = makeTmpDir (
15+ 'graphql-js-benchmark-cache' ,
16+ false ,
17+ ) ;
1418
1519 return revisionList . map ( ( revision ) => {
20+ // Resolve refs like "main" to full SHAs so equivalent revisions reuse setup.
21+ const hash = revision === LOCAL ? LOCAL : git ( ) . revParse ( revision ) ;
22+ const projectPath = tmpDirPath ( 'setup' , hash ) ;
23+ if ( fs . existsSync ( projectPath ) ) {
24+ return { revision, projectPath } ;
25+ }
26+
1627 console . log ( `\u{1F373} Preparing ${ revision } ...` ) ;
17- const projectPath = tmpDirPath ( 'setup' , revision ) ;
18- fs . rmSync ( projectPath , { recursive : true , force : true } ) ;
1928 fs . mkdirSync ( projectPath , { recursive : true } ) ;
2029
2130 fs . cpSync ( localRepoPath ( 'benchmark' ) , path . join ( projectPath , 'benchmark' ) , {
@@ -29,7 +38,7 @@ export function prepareBenchmarkProjects(
2938 private : true ,
3039 type : 'module' ,
3140 dependencies : {
32- graphql : prepareNPMPackage ( revision ) ,
41+ graphql : prepareNPMPackage ( hash ) ,
3342 } ,
3443 } ,
3544 null ,
@@ -41,18 +50,15 @@ export function prepareBenchmarkProjects(
4150 return { revision, projectPath } ;
4251 } ) ;
4352
44- function prepareNPMPackage ( revision : string ) : string {
45- if ( revision === LOCAL ) {
53+ function prepareNPMPackage ( hash : string ) : string {
54+ if ( hash === LOCAL ) {
4655 const repoDir = localRepoPath ( ) ;
4756 const archivePath = tmpDirPath ( 'graphql-local.tgz' ) ;
4857 fs . renameSync ( buildNPMArchive ( repoDir ) , archivePath ) ;
4958 return archivePath ;
5059 }
5160
52- // Returns the complete git hash for a given git revision reference.
53- const hash = git ( ) . revParse ( revision ) ;
54-
55- const archivePath = tmpDirPath ( `graphql-${ hash } .tgz` ) ;
61+ const archivePath = benchmarkCachePath ( `graphql-${ hash } .tgz` ) ;
5662 if ( fs . existsSync ( archivePath ) ) {
5763 return archivePath ;
5864 }
0 commit comments