Skip to content

perf: add lifecycle cancellation for Activity renderLoop requestAnimationFrame #6133

@Rohit-rk07

Description

@Rohit-rk07

Summary

Activity starts a recursive requestAnimationFrame(renderLoop) that runs for the full page lifetime, but there is no tracked RAF id/cancel path for this loop.

Code references

  • js/activity.js:504 (const renderLoop = () => { ... })
  • js/activity.js:514 (requestAnimationFrame(renderLoop); inside loop)
  • js/activity.js:516 (initial requestAnimationFrame(renderLoop);)

Why this matters

Even with dirty-checks, the RAF callback itself still executes every frame. Without explicit lifecycle cleanup, this can:

  • keep scheduling work when Activity is torn down/reinitialized,
  • create duplicate loops in edge re-init flows,
  • waste CPU on low-power devices.

Expected behavior

  • Store RAF id (e.g. this._renderLoopRafId) when scheduling.
  • Gate loop with a lifecycle flag (e.g. this._isRunning).
  • Cancel RAF on teardown/destroy path (cancelAnimationFrame).

Suggested fix sketch

  • Replace naked recursive calls with a managed startRenderLoop() / stopRenderLoop() pair.
  • Ensure stopRenderLoop() is invoked from Activity cleanup/unload hooks.

Optional validation

  • Add a unit/integration check that reinitializing Activity does not increase active RAF loop count.

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