Skip to content

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

Description

@SableRaf

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Completed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions