Browser VBlank waits follow requestAnimationFrame frequency in PS1 timing mode
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c
- Domain
- backend, performance
Research direction
Read psyz/src/platform/sdl3_common.h::WaitForNextFrame and psyz/src/web/web_timing.c to trace how browser callbacks and emulated VBlank timing interact. Start by reproducing the issue with the presentation sample and its controlled timer diagnostic; compare iteration rates at different callback frequencies. Done when internal-limiter PS1 timing follows emulated time within host performance limits, with presentation cadence treated separately.
Written by the indexing model from the issue text.
Description
In PsyZ 35c673ecf1c4ba799a812d701918c2c52935475b, the browser branch of
WaitForNextFrame waits for one requestAnimationFrame callback per requested
VBlank. It does not use the emulated NTSC/PAL duration there, even when
PSYZ_VSYNC_OFF selects the internal limiter.
Reproduction
Run the shared presentation sample, which selects
NTSC, the internal limiter and a two-VBlank wait per application iteration.
On actual hardware, compare it on different display refresh rates.
For a repeatable software diagnostic, measure.js replaces RAF with
a controlled timer callback before loading the sample. The measured iteration
rate changes substantially with callback frequency:
| Requested callback rate | Unmodified PsyZ | Local timing prototype |
|---|---|---|
| 30/s | 13.3/s | 25.8/s |
| 60/s | 25.4/s | 28.3/s |
| 120/s | 44.1/s | 28.3/s |
These are software-timer measurements in headless Chromium, not physical
30/60/120 Hz monitor measurements. Timer, main-loop and rendering overhead are
included. The NTSC two-VBlank target is about 29.97 iterations/s; the local
prototype is closer but this test does not establish perfect pacing.
Expected behavior and scope
Internal-limiter/PS1 timing should be governed by emulated time, independently
of callback frequency, within host performance limits. Presentation cadence and
emulated VBlank advancement are separate concerns. Explicit display-sync or
uncapped modes may intentionally behave differently.
The relevant paths are psyz/src/platform/sdl3_common.h::WaitForNextFrame and
psyz/src/web/web_timing.c. Our current delay-based workaround is evidence for
the diagnosis, not a complete solution for one-VBlank loops, background tabs,
PAL, variable refresh or catch-up policy.
To run the optional timer experiment, install playwright in a scratch directory, save the attached script as measure.cjs (CommonJS), and run:
node measure.cjs http://127.0.0.1:8201/index.html
Set CHROME to your installed Chromium executable, or install Playwright's Chromium with npx playwright install chromium. The script overrides RAF only in its isolated test pages.
Recorded browser environment: Emscripten 6.0.13, Chromium 157 (headless SwiftShader), macOS arm64, device scale factor 1. Comparisons use local port prototypes, not hardware reference captures.
Build and run the standalone presentation sample
Download presentation.c and shell.html into the same directory. No game source, executable or assets are needed. Add this CMakeLists.txt:
cmake_minimum_required(VERSION 3.21)
project(presentation_repro C CXX)
set(CMAKE_C_STANDARD 11)
add_compile_options(-pthread)
add_link_options(-pthread)
set(SDL_PTHREADS ON CACHE BOOL "" FORCE)
add_subdirectory("${PSYZ_ROOT}/psyz" psyz EXCLUDE_FROM_ALL)
add_executable(presentation presentation.c)
target_link_libraries(presentation PRIVATE psyz)
target_link_options(presentation PRIVATE -sASSERTIONS=1 -sPTHREAD_POOL_SIZE=2)
psyz_web_configure_target(presentation OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/site")
get_target_property(options presentation LINK_OPTIONS)
list(FILTER options EXCLUDE REGEX "^--shell-file=")
set_property(TARGET presentation PROPERTY LINK_OPTIONS "${options}")
target_link_options(presentation PRIVATE "--shell-file=${CMAKE_CURRENT_https://github.com/user-attachments/files/34581629/presentation.c_DIR}/shell.html")
Use a PsyZ checkout at the recorded revision, with its SDL submodule initialized:
emcmake cmake -S . -B build -DPSYZ_ROOT=/path/to/psyz -DCMAKE_BUILD_TYPE=Release
cmake --build build -j8
Serve build/site locally with Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp, as required by Emscripten pthreads, then open index.html.
- Dominant language
- C
- Stars
- 107
- Forks
- 26
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 5
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Xeeynamo/psyz
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
Difficulty 5/5 Over a week Newbie friendliness 38/100
Similar issues
-
GXF: heap buffer overflow in parse_ad_cdp() — unbounded cc_count in CDP cc data sectionPossibly taken @pranayr710 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
CCExtractor/ccextractor#2498 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
area: services kind: bug preview-effort: small priority: low
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Static Analysis failurePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100