Skip to content

perf: clean up idle watcher listeners/interval to avoid duplicate background work #6140

@Rohit-rk07

Description

@Rohit-rk07

Summary

_initIdleWatcher in js/activity.js adds multiple global event listeners and a periodic setInterval, but the cleanup path is not managed through Activity lifecycle teardown.

Code references

  • js/activity.js:2952 (this._initIdleWatcher = () => { ... })
  • js/activity.js:2972 window.addEventListener(mousemove, resetIdleTimer);
  • js/activity.js:2973 window.addEventListener(mousedown, resetIdleTimer);
  • js/activity.js:2974 window.addEventListener(keydown, resetIdleTimer);
  • js/activity.js:2975 window.addEventListener(touchstart, resetIdleTimer);
  • js/activity.js:2976 window.addEventListener(wheel, resetIdleTimer);
  • js/activity.js:2979 setInterval(() => { ... }, 1000);

Why this matters

If Activity is reinitialized/reset in the same page session, additional listeners and intervals can accumulate, causing duplicated work, extra wakeups, and unnecessary CPU/battery use.

Expected behavior

  • Track idle watcher listener handlers and interval id.
  • Register listeners via managed lifecycle utilities (addEventListener tracker or equivalent).
  • Clear the interval and detach listeners during teardown/reset.

Suggested fix

Introduce startIdleWatcher() / stopIdleWatcher() (or equivalent) and call stop in existing cleanup paths before reinit.

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