Skip to content

[p5.js 2.0 Bug Report]: Global function getter is slower than 1.xΒ #8017

@Papershine

Description

@Papershine

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.0.3

Web browser and version

Chrome 138.0.7204.169 (Official Build) (arm64)

Operating system

MacOS Sequoia 15.5

Steps to reproduce this

Because of #8013, I ran a couple of performance profiles on the sketch there and noticed something weird - the traces point to get in bindGlobal taking up a lot of time,

This is a screenshot of the profile of the sketch shared by @davepagurek in that thread

1.x 2.x
Image Image

Notice how the calls to floor and random are significantly slower.

See this test just calling random:

https://editor.p5js.org/Papershine/sketches/Feun-KSzF

On 2.0 it takes around 140ms while on 1.11 it takes around 10ms.

Maybe the call to bind every time the function is called might be causing issues?

p5.js/src/core/main.js

Lines 105 to 110 in 5ef51ca

get: () => {
if(typeof this[property] === 'function'){
return this[property].bind(this);
}else{
return this[property];
}

I'm not sure if this behaviour is intended, but might be worth discussing!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions