forked from PrismarineJS/prismarine-web-client
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial implementation that should work already!
- Loading branch information
Showing
14 changed files
with
253 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Vercel Deploy Preview | ||
env: | ||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | ||
on: | ||
issue_comment: | ||
types: [created] | ||
push: | ||
branches: | ||
- perf-test | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
# todo skip already created deploys on that commit | ||
if: >- | ||
github.event.issue.pull_request != '' && | ||
( | ||
contains(github.event.comment.body, '/benchmark') | ||
) | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: refs/pull/${{ github.event.issue.number }}/head | ||
- run: npm i -g pnpm@9.0.4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
cache: "pnpm" | ||
- run: pnpm install | ||
- run: pnpm build | ||
- run: pnpm test:benchmark | ||
# read benchmark results from stdout | ||
- run: echo "BENCHMARK_RESULT=$(cat benchmark.txt)" >> $GITHUB_ENV | ||
- uses: mshick/add-pr-comment@v2 | ||
with: | ||
allow-repeats: true | ||
message: | | ||
Benchmark result: ${{ env.BENCHMARK_RESULT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// <reference types="cypress" /> | ||
import { BenchmarkAdapter } from '../../src/benchmarkAdapter' | ||
import { setOptions, cleanVisit, visit } from './shared' | ||
|
||
it('Benchmark rendering performance', () => { | ||
cleanVisit('/?openBenchmark=true&renderDistance=5') | ||
// wait for render end event | ||
return cy.document().then({ timeout: 120_000 }, doc => { | ||
return new Cypress.Promise(resolve => { | ||
cy.log('Waiting for world to load') | ||
doc.addEventListener('cypress-world-ready', resolve) | ||
}).then(() => { | ||
cy.log('World loaded') | ||
}) | ||
}).then(() => { | ||
cy.window().then(win => { | ||
const adapter = win.benchmarkAdapter as BenchmarkAdapter | ||
const renderTimeWorst = adapter.worstRenderTime | ||
const renderTimeAvg = adapter.averageRenderTime | ||
const fpsWorst = 1000 / renderTimeWorst | ||
const fpsAvg = 1000 / renderTimeAvg | ||
const totalTime = adapter.worldLoadTime | ||
|
||
const messages = [ | ||
`Worst FPS: ${fpsWorst.toFixed(2)}`, | ||
`Average FPS: ${fpsAvg.toFixed(2)}`, | ||
`Total time: ${totalTime.toFixed(2)}s`, | ||
`Memory usage average: ${adapter.memoryUsageAverage.toFixed(2)}MB`, | ||
`Memory usage worst: ${adapter.memoryUsageWorst.toFixed(2)}MB`, | ||
] | ||
for (const message of messages) { | ||
cy.log(message) | ||
} | ||
cy.writeFile('benchmark.txt', messages.join('\n')) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Vec3 } from 'vec3' | ||
import { downloadAndOpenFileFromUrl } from './downloadAndOpenFile' | ||
import { activeModalStack, miscUiState } from './globalState' | ||
import { options } from './optionsStorage' | ||
import { BenchmarkAdapter } from './benchmarkAdapter' | ||
|
||
const testWorldFixtureUrl = 'https://bucket.mcraft.fun/Future CITY 4.4-slim.zip' | ||
const testWorldFixtureSpawn = [-133, 87, 309] as const | ||
|
||
export const openBenchmark = async (renderDistance = 8) => { | ||
let memoryUsageAverage = 0 | ||
let memoryUsageSamples = 0 | ||
let memoryUsageWorst = 0 | ||
setInterval(() => { | ||
const memoryUsage = (window.performance as any)?.memory?.usedJSHeapSize | ||
if (memoryUsage) { | ||
memoryUsageAverage = (memoryUsageAverage * memoryUsageSamples + memoryUsage) / (memoryUsageSamples + 1) | ||
memoryUsageSamples++ | ||
if (memoryUsage > memoryUsageWorst) { | ||
memoryUsageWorst = memoryUsage | ||
} | ||
} | ||
}, 200) | ||
|
||
const benchmarkAdapter: BenchmarkAdapter = { | ||
get worldLoadTime () { | ||
return window.worldLoadTime | ||
}, | ||
get averageRenderTime () { | ||
return window.viewer.world.avgRenderTime | ||
}, | ||
get worstRenderTime () { | ||
return window.viewer.world.worstRenderTime | ||
}, | ||
get memoryUsageAverage () { | ||
return memoryUsageAverage | ||
}, | ||
get memoryUsageWorst () { | ||
return memoryUsageWorst | ||
} | ||
} | ||
window.benchmarkAdapter = benchmarkAdapter | ||
|
||
options.renderDistance = renderDistance | ||
void downloadAndOpenFileFromUrl(testWorldFixtureUrl, undefined, { | ||
connectEvents: { | ||
serverCreated () { | ||
if (testWorldFixtureSpawn) { | ||
localServer!.spawnPoint = new Vec3(...testWorldFixtureSpawn) | ||
localServer!.on('newPlayer', (player) => { | ||
player.on('dataLoaded', () => { | ||
player.position = new Vec3(...testWorldFixtureSpawn) | ||
}) | ||
}) | ||
} | ||
}, | ||
} | ||
}) | ||
} | ||
|
||
export const registerOpenBenchmarkListener = () => { | ||
const params = new URLSearchParams(window.location.search) | ||
if (params.get('openBenchmark')) { | ||
void openBenchmark(params.has('renderDistance') ? +params.get('renderDistance')! : undefined) | ||
} | ||
|
||
window.addEventListener('keydown', (e) => { | ||
if (e.code === 'KeyB' && e.shiftKey && !miscUiState.gameLoaded && activeModalStack.length === 0) { | ||
e.preventDefault() | ||
void openBenchmark() | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface BenchmarkAdapter { | ||
worldLoadTime: number | ||
averageRenderTime: number | ||
worstRenderTime: number | ||
memoryUsageAverage: number | ||
memoryUsageWorst: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
export type ConnectOptions = { | ||
server?: string; | ||
singleplayer?: any; | ||
username: string; | ||
password?: any; | ||
proxy?: any; | ||
botVersion?: any; | ||
serverOverrides?; | ||
serverOverridesFlat?; | ||
peerId?: string; | ||
ignoreQs?: boolean; | ||
server?: string | ||
singleplayer?: any | ||
username: string | ||
password?: any | ||
proxy?: any | ||
botVersion?: any | ||
serverOverrides? | ||
serverOverridesFlat? | ||
peerId?: string | ||
ignoreQs?: boolean | ||
onSuccessfulPlay?: () => void | ||
autoLoginPassword?: string | ||
serverIndex?: string | ||
|
||
connectEvents?: { | ||
serverCreated?: () => void | ||
// connect: () => void; | ||
// disconnect: () => void; | ||
// error: (err: any) => void; | ||
// ready: () => void; | ||
// end: () => void; | ||
} | ||
} |
Oops, something went wrong.