Skip to content

Commit 6d900d4

Browse files
authored
Update dependencies and switch from Puppeteer to Playwright (#32)
1 parent b88a503 commit 6d900d4

File tree

9 files changed

+4227
-650
lines changed

9 files changed

+4227
-650
lines changed

.yarn/releases/yarn-3.2.1.cjs

Lines changed: 786 additions & 0 deletions
Large diffs are not rendered by default.

.yarn/releases/yarn-berry.cjs

Lines changed: 0 additions & 55 deletions
This file was deleted.

.yarnrc.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ nodeLinker: node-modules
22

33
plugins:
44
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
5-
spec: '@yarnpkg/plugin-workspace-tools'
5+
spec: "@yarnpkg/plugin-workspace-tools"
66
- path: .yarn/plugins/@yarnpkg/plugin-compat.cjs
7-
spec: '@yarnpkg/plugin-compat'
7+
spec: "@yarnpkg/plugin-compat"
88

9-
yarnPath: .yarn/releases/yarn-berry.cjs
9+
yarnPath: .yarn/releases/yarn-3.2.1.cjs

package.json

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "benchmark suite and runner for react-redux",
55
"main": "index.js",
66
"scripts": {
7-
"start": "node ./runBenchmarks.js",
8-
"format": "prettier --write \"sources/**/src/*.{js,jsx}\" *.js",
7+
"start": "tsx ./runBenchmarks.ts",
8+
"format": "prettier --write \"sources/**/src/*.{js,jsx,ts,tsx}\" *.js",
99
"build": "node scripts/cli.js"
1010
},
1111
"repository": {
@@ -24,7 +24,8 @@
2424
},
2525
"homepage": "https://github.com/reduxjs/react-redux-benchmarks#readme",
2626
"dependencies": {
27-
"@reduxjs/toolkit": "^1.6.1",
27+
"@reduxjs/toolkit": "^1.9.5",
28+
"@replayio/playwright": "^1.0.3",
2829
"@testing-library/dom": "^8.5.0",
2930
"@testing-library/user-event": "^13.2.1",
3031
"chance": "^1.1.8",
@@ -35,31 +36,38 @@
3536
"fps-emitter": "^1.0.0",
3637
"glob": "^7.1.3",
3738
"performance-mark-metadata": "^1.0.3",
38-
"puppeteer": "^1.7.0",
39-
"react": "0.0.0-experimental-5a0607278-20210922",
40-
"react-dom": "0.0.0-experimental-5a0607278-20210922",
41-
"react-redux": "file:.yalc/react-redux",
39+
"playwright": "^1.35.1",
40+
"puppeteer": "latest",
41+
"react": "^18.2.0",
42+
"react-dom": "^18.2.0",
43+
"react-redux": "^8.1.0",
4244
"react-redux-5.1.2": "npm:[email protected]",
4345
"react-redux-6.0.1": "npm:[email protected]",
4446
"react-redux-7.2.5": "npm:[email protected]",
45-
"react-redux-8.0.0-alpha.0": "file:.yalc/react-redux",
47+
"react-redux-8.1.0": "npm:react-redux@8.1.0",
4648
"recursive-copy": "^2.0.9",
4749
"redux": "^4.1.1",
4850
"reselect": "^4.0.0",
4951
"seedrandom": "^3.0.5",
5052
"tracealyzer": "^0.9.3",
51-
"use-sync-external-store": "0.0.0-experimental-5a0607278-20210922"
53+
"tsx": "^3.12.7",
54+
"use-sync-external-store": "latest"
5255
},
5356
"devDependencies": {
57+
"@types/cli-table2": "^0.2.3",
58+
"@types/express": "^4.17.17",
5459
"@types/fs-extra": "^9.0.12",
60+
"@types/glob": "^8.1.0",
61+
"@types/lodash": "^4.14.195",
62+
"@types/puppeteer": "^7.0.4",
5563
"@types/react": "^17.0.21",
5664
"@types/react-dom": "^17.0.9",
57-
"@types/yargs": "^17.0.2",
58-
"esbuild": "^0.12.28",
65+
"@types/yargs": "^17.0.24",
66+
"esbuild": "^0.17",
5967
"esbuild-plugin-alias": "^0.1.2",
6068
"fs-extra": "^10.0.0",
6169
"prettier": "latest",
62-
"typescript": "^4.4.3",
70+
"typescript": "^5.1.0",
6371
"yargs": "^17.1.1"
6472
}
6573
}

runBenchmarks.js renamed to runBenchmarks.ts

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
/* eslint no-console: 0 */
22
'use strict'
33

4-
const path = require('path')
5-
const puppeteer = require('puppeteer')
6-
const fs = require('fs')
7-
const Table = require('cli-table2')
8-
const _ = require('lodash')
9-
const glob = require('glob')
10-
const yargs = require('yargs/yargs')
11-
12-
const serverUtils = require('./utils/server.js')
13-
14-
const readFolderNames = (searchDir) => {
4+
import path from 'path'
5+
import puppeteer from 'puppeteer'
6+
import playwright from 'playwright'
7+
import fs from 'fs'
8+
import Table from 'cli-table2'
9+
import _ from 'lodash'
10+
import glob from 'glob'
11+
import yargs from 'yargs/yargs'
12+
13+
import {
14+
capturePageStats,
15+
ProcessedFPSEntry,
16+
runServer,
17+
PageStatsResult,
18+
RenderResult,
19+
} from './utils/server'
20+
21+
const readFolderNames = (searchDir: string) => {
1522
return glob.sync('*/', { cwd: searchDir }).map((s) => s.replace('/', ''))
1623
}
1724

@@ -51,26 +58,27 @@ const args = yargs(process.argv.slice(2))
5158

5259
// Given an array of items such as ["a", "b", "c", "d"], return the pairwise entries
5360
// in the form [ ["a","b"], ["b","c"], ["c","d"] ]
54-
function pairwise(list) {
61+
function pairwise<T>(list: T[]): [T, T][] {
5562
// Create a new list offset by 1
56-
var allButFirst = _.rest(list)
63+
// @ts-ignore
64+
const allButFirst: T[] = _.rest(list)
5765
// Pair up entries at each index
58-
var zipped = _.zip(list, allButFirst)
66+
const zipped = _.zip(list, allButFirst)
5967
// Remove last entry, as there's a mismatch from the offset
60-
var pairwiseEntries = _.initial(zipped)
68+
const pairwiseEntries = _.initial(zipped) as [T, T][]
6169
return pairwiseEntries
6270
}
6371

6472
function printBenchmarkResults(benchmark, versionPerfEntries, trace) {
6573
console.log(`\nResults for benchmark ${benchmark}:`)
6674

67-
let traceCategories = []
75+
let traceCategories: string[] = []
6876

6977
if (trace) {
7078
traceCategories = ['Scripting', 'Rendering', 'Painting']
7179
}
7280

73-
const table = new Table({
81+
const table: any = new Table({
7482
head: [
7583
'Version',
7684
'Avg FPS',
@@ -87,7 +95,7 @@ function printBenchmarkResults(benchmark, versionPerfEntries, trace) {
8795

8896
const { fps, profile, mountTime, averageUpdateTime } = versionResults
8997

90-
let traceResults = []
98+
let traceResults: number[] = []
9199

92100
if (trace) {
93101
traceResults = [
@@ -112,10 +120,15 @@ function printBenchmarkResults(benchmark, versionPerfEntries, trace) {
112120
}
113121

114122
function calculateBenchmarkStats(
115-
fpsRunResults,
116-
categories,
123+
fpsRunResults: {
124+
fpsValues: ProcessedFPSEntry[]
125+
start: number
126+
end: number
127+
reactTimingEntries: RenderResult[]
128+
},
129+
categories: string[],
117130
traceRunResults,
118-
trace
131+
trace: boolean
119132
) {
120133
const { fpsValues, start, end } = fpsRunResults
121134

@@ -138,19 +151,24 @@ function calculateBenchmarkStats(
138151
const duration = second.timestamp - first.timestamp
139152
const durationSeconds = duration / 1000.0
140153

141-
return { FPS: first.FPS, durationSeconds }
154+
return { FPS: first.FPS, durationSeconds, weightedFPS: 0 }
142155
})
143156

144157
const sums = fpsValuesWithDurations.reduce(
145158
(prev, current) => {
146159
const weightedFPS = current.FPS * current.durationSeconds
147160

148161
return {
162+
FPS: current.FPS,
149163
weightedFPS: prev.weightedFPS + weightedFPS,
150164
durationSeconds: prev.durationSeconds + current.durationSeconds,
151165
}
152166
},
153-
{ FPS: 0, weightedFPS: 0, durationSeconds: 0 }
167+
{ FPS: 0, weightedFPS: 0, durationSeconds: 0 } as {
168+
FPS: number
169+
weightedFPS: number
170+
durationSeconds: number
171+
}
154172
)
155173

156174
const weightedFPS = sums.weightedFPS / sums.durationSeconds
@@ -170,10 +188,20 @@ function calculateBenchmarkStats(
170188
return { fps, profile: { categories }, mountTime, averageUpdateTime }
171189
}
172190

173-
async function runBenchmarks({ scenarios, versions, length, trace }) {
191+
async function runBenchmarks({
192+
scenarios,
193+
versions,
194+
length,
195+
trace,
196+
}: {
197+
scenarios: string[]
198+
versions: string[]
199+
length: number
200+
trace: boolean
201+
}) {
174202
console.log('Scenarios: ', scenarios)
175203
const distFolder = path.resolve('dist')
176-
const server = await serverUtils.runServer(9999, distFolder)
204+
const server = await runServer(9999, distFolder)
177205

178206
for (let scenario of scenarios) {
179207
const versionPerfEntries = {}
@@ -182,8 +210,8 @@ async function runBenchmarks({ scenarios, versions, length, trace }) {
182210

183211
for (let version of versions) {
184212
console.log(` React-Redux version: ${version}`)
185-
const browser = await puppeteer.launch({
186-
//headless: false
213+
const browser = await playwright.chromium.launch({
214+
headless: true,
187215
})
188216

189217
const folderPath = path.join(distFolder, version, scenario)
@@ -198,14 +226,15 @@ async function runBenchmarks({ scenarios, versions, length, trace }) {
198226
const URL = `http://localhost:9999/${version}/${scenario}`
199227
try {
200228
console.log(` Checking max FPS... (${length} seconds)`)
201-
const fpsRunResults = await serverUtils.capturePageStats(
229+
const fpsRunResults = await capturePageStats(
202230
browser,
203231
URL,
204232
null,
205233
length * 1000
206234
)
207235

208-
let traceRunResults, categories
236+
let traceRunResults: PageStatsResult | undefined
237+
let categories: string[] = []
209238

210239
if (trace) {
211240
console.log(` Running trace... (${length} seconds)`)
@@ -214,7 +243,7 @@ async function runBenchmarks({ scenarios, versions, length, trace }) {
214243
'runs',
215244
`trace-${scenario}-${version}.json`
216245
)
217-
traceRunResults = await serverUtils.capturePageStats(
246+
traceRunResults = await capturePageStats(
218247
browser,
219248
URL,
220249
traceFilename,
@@ -242,4 +271,5 @@ async function runBenchmarks({ scenarios, versions, length, trace }) {
242271
process.exit(0)
243272
}
244273

274+
// @ts-ignore
245275
runBenchmarks(args.argv)

scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const args = yargs(process.argv.slice(2)).options('concurrent', {
1616
alias: 'c',
1717
describe: "Use React 18's `createRoot` rendering",
1818
type: 'boolean',
19-
default: false,
19+
default: true,
2020
})
2121

2222
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

utils/server.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)