Skip to content

color() is unnecessarily slow #2830

@Spongman

Description

@Spongman

0.6.1

the implementation of color() uses map() (inside _parseInputs and _calculateLevels) to loop through the color components for scaling/clamping operations.

in a simple test case:

p5.disableFriendlyErrors = true;
function setup() {
  createCanvas(100, 100);
}
function draw() {
  for (var i = 0; i < 100000; i++)
    color([255,0,100,255]);
}

these map call result in >90% of total CPU usage:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions