Skip to content

Unknown value of 0 means "assume slow" but example shows "assume fast" #5

Open

Description

@mmocny

I can image websites progressively enhancing with effects using code such as:

const minCpuLevel = 2;
if (navigator.cpuPerformance > minCpuLevel) {
  // add sparkles
}

But for any devices with unknown value of 0, this would not be enabled, unless explicitly tested for.

Should the Unknown special value be some large constant or Number.MAX_SAFE_INTEGER?

Activity

  1. nickie commented on Nov 13, 2025

    @nickie
    Collaborator

    The logic for the "unknown" bucket should be left to the app to decide.
    "Infinitely slow" and "infinitely fast" are two arbitrary interpretations.
    Maybe the latter makes more sense, hence it is used in the example.
    But the value 0 should be just treated as a special case.

    If an app wants to interpret this as "infinitely fast", what would be the issue with the following code?

    const minCpuLevel = 2;
    if (navigator.cpuPerformance > minCpuLevel || navigator.cpuPerformance == 0) {
      // add sparkles
    }
  2. mmocny commented on Nov 14, 2025

    @mmocny
    Author

    No issue for a well written application that is written by a developer who knows to explicitly test.

    But given that there is a strict ordering of performance levels, and also that we are proposing adding new buckets over time-- I don't see it likely that a developer would explicitly "switch" on specific performance levels, but instead would use a simple "less than" comparison, and "0" being the smallest feels like the wrong default to me.

    The choice might lead to sites unknowingly having disabled functionality, by default, and assume it would not be performance (this is the opposite of what sites do today).


    I don't know how commonly a value of 0 would be used, so perhaps this is not a necessary concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions