Skip to content

fix: fix CPU issue in dot animations#42

Merged
khaosdoctor merged 2 commits into
mainfrom
fix-cpu-issue
May 6, 2026
Merged

fix: fix CPU issue in dot animations#42
khaosdoctor merged 2 commits into
mainfrom
fix-cpu-issue

Conversation

@khaosdoctor
Copy link
Copy Markdown
Member

Problem: The Brazil flag dot canvas was causing high GPU usage (59%+) and page-wide hangs due to three issues in canvas.ts:

  1. All 7,672 dots were submitted to the canvas 2D API every frame, even dots not yet visible (progress === 0)
  2. Each dot used roundRect + fill — complex GPU path rasterization — instead of a simple fillRect primitive
  3. The canvas was sized with devicePixelRatio multiplied on top of an already CSS-scaled element (scale(1.5)), inflating the texture to ~4× the visible area on Retina displays

Changes: Skip invisible dots before drawing, replace roundRect with fillRect, and remove the devicePixelRatio multiplier from canvas sizing.

Skip drawing dots with zero progress, replace roundRect with fillRect
to eliminate complex path rasterization, and drop devicePixelRatio
scaling to avoid allocating an oversized canvas texture on Retina displays.
Copilot AI review requested due to automatic review settings May 6, 2026 17:56
@wellwelwel wellwelwel changed the title Fix CPU issue in dot animations fix: fix CPU issue in dot animations May 6, 2026
Copy link
Copy Markdown
Member

@wellwelwel wellwelwel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testei localmente, mas mudou muito o esquema da animação para algo mais engessado de certa forma. Sobre pular os que não estão visíveis, a ideia é legal, mas é típico da IA mexer em mais coisas do que precisa. Acredito que a mudança de cálculo com a remoção do arredondamento fez a animação apenas "mostrar" vs. "não mostrar" ao invés de ter uma suavidade, mesmo que discreta.

Em termos artísticos, eu diria que essa mudança da IA tirou totalmente a alma da animação, mesmo que pareça bastante com a ideia original.

@wellwelwel wellwelwel marked this pull request as draft May 6, 2026 20:03
@khaosdoctor
Copy link
Copy Markdown
Member Author

Na verdade eu testei só com a remoção da visibilidade e o problema continuou. O que resolveu foi remover o cálculo de pixel resolution mesmo

@wellwelwel wellwelwel marked this pull request as ready for review May 6, 2026 20:32
@khaosdoctor khaosdoctor merged commit ac6ba1d into main May 6, 2026
5 checks passed
@khaosdoctor khaosdoctor deleted the fix-cpu-issue branch May 6, 2026 21:17
khaosdoctor added a commit that referenced this pull request May 10, 2026
khaosdoctor added a commit that referenced this pull request May 11, 2026
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.

2 participants