[p5.js 2.0+ Bug Report]: Large slowdown in `p5.Graphics.set()` compared to v1.11.x
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- WebGPU
- p5.strands
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
2.3.0
Web browser and version
- Chrome Version 151.0.7922.34 (Official Build) (arm64)
- Safari Version 26.5.2 (21624.2.5.11.8)
- Firefox 152.0.4 (aarch64)
Operating system
macOS 26.5.2 (25F84) Tahoe
Steps to reproduce this
Description
Calling set() on a p5.Graphics buffer is considerably slower in p5.js 2.3.0 than in 1.11.12. Note: directly modifying pixels[] performs about the same in both versions.
I first noticed the issue when trying to run the following sketch in p5.js 2.3.0: https://openprocessing.org/@megamitts/2979162
Benchmark
I made a quickly vibe coded benchmark sketch to systematically test the issue. It updates a 100 × 100 p5.Graphics buffer over multiple frames and prints the averaged results to the console.
In this test in Chrome, set() was about 6.9 times slower in 2.3.0 than in 1.11.12.
| p5.js version | set() |
pixels[] |
set() slowdown vs pixels[] |
|---|---|---|---|
| 1.11.12 | 1.85 ms | 1.10 ms | 1.7× |
| 2.3.0 | 12.79 ms | 1.16 ms | 11× |
I got comparable results, with slowdowns between ~9× and ~17×, in Safari and Firefox.
Reproduction
Run the benchmark sketch in p5.js 1.11.x, then in 2.x
Contributor guide
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.
Research direction
Start by running the linked benchmark sketch against p5.js 1.11.12 and 2.3.0, focusing on p5.Graphics.set() and the reported 100 × 100 buffer case. Trace the p5.Graphics.set() implementation and compare its behavior between versions. Done means the benchmark no longer shows the large 2.x slowdown while updating the graphics buffer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100