ITADN

[p5.js 2.0+ Bug Report]: Large slowdown in `p5.Graphics.set()` compared to v1.11.x

#9000OpenSableRaf 创建于 2026-07-21
Area:CoreArea:Imagep5.js 2.0+Technical InitiativePatch
S
SableRafcommented
### Most appropriate sub-area of p5.js? - [ ] Accessibility - [ ] Color - [x] Core/Environment/Rendering - [ ] Data - [ ] DOM - [ ] Events - [x] 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](https://editor.p5js.org/SableRaf/sketches/LeRg5yh7C) 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](https://editor.p5js.org/SableRaf/sketches/LeRg5yh7C) sketch in p5.js 1.11.x, then in 2.x
2 条评论