Skip to content

perf: add willReadFrequently hint to canvas context#270

Open
VoidArchive wants to merge 1 commit into
nimiq:masterfrom
VoidArchive:fix/canvas-willreadfrequently
Open

perf: add willReadFrequently hint to canvas context#270
VoidArchive wants to merge 1 commit into
nimiq:masterfrom
VoidArchive:fix/canvas-willreadfrequently

Conversation

@VoidArchive

Copy link
Copy Markdown

Summary

Adds willReadFrequently: true to the canvas 2D context creation to eliminate the Chrome warning and potentially improve scanning performance.

Problem

Chrome shows this warning during QR scanning:

Canvas2D: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true.

Solution

Add the willReadFrequently: true option when creating the canvas context in _drawToCanvas().

Browser Support

The willReadFrequently option is supported in all modern browsers:

  • Chrome 97+
  • Firefox 97+
  • Safari 15.4+
  • Edge 97+

For older browsers, the option is simply ignored (no breaking change).

Fixes #236
Fixes #251

Fixes Chrome warning about multiple getImageData readback operations.
  This optimization hint tells the browser to prepare for frequent
  pixel reads, improving performance for QR scanning.

  Fixes nimiq#236
  Fixes nimiq#251
  3. PR title: perf: add willReadFrequently hint to canvas context
  4. PR description:
  ## Summary
  Adds `willReadFrequently: true` to the canvas 2D context creation to
eliminate
  the Chrome warning and potentially improve scanning performance.

  ## Problem
  Chrome shows this warning during QR scanning:
  > Canvas2D: Multiple readback operations using getImageData are faster
with
  > the willReadFrequently attribute set to true.

  ## Solution
  Add the `willReadFrequently: true` option when creating the canvas
context
  in `_drawToCanvas()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any reason the "willReadFrequently" flag is not being used? Optimization - use willReadFrequently when initializing canvas

1 participant