Skip to content

perf(web-watcher): rate-limit page-title lookups - #345

Merged
ErikBjare merged 4 commits into
ActivityWatch:masterfrom
0xbrayo:perf/web-watcher-title-lookup
Oct 11, 2026
Merged

ErikBjare merged 4 commits into
ActivityWatch:masterfrom
0xbrayo:perf/web-watcher-title-lookup

Conversation

@0xbrayo

@0xbrayo 0xbrayo commented Oct 8, 2026

Copy link
Copy Markdown
Member

Part of #333.

WebWatcher subscribes to typeWindowContentChanged, which a browser emits up to every 100 ms (notificationTimeout) while a page is loading or animating. For every such event it ran findWebView, a bounded walk of the event's subtree of up to MAX_TRAVERSAL_NODES (2000) getChild binder calls, on the accessibility service's main thread. For Firefox the walk can never match (documented on findWebView), so it was pure cost.

Change

  • Skip the title lookup for Firefox.
  • For other browsers, look the title up at most every 500 ms while the current page's title is still unknown, and every 5 s once it has been found, so in-page title changes are still picked up. The URL extraction itself is unchanged and still runs on every event.
  • BrowserSessionTracker exposes hasTitle (title seen since the URL last changed).

Testing

  • ./gradlew :mobile:testStandardDebugUnitTest passes.
  • The rate limit sits inside the accessibility service and depends on live node trees, so this has no new unit test.

@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking issue was found.

Summary

This PR limits page-title searches while keeping URL extraction unchanged.

  • WebWatcher spaces out page-title searches and skips them for Firefox.

Reviews (5) · Last reviewed commit: "fix(web-watcher): let an earlier title f..." · Reviewed by Greptile

Comment thread mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt Outdated
Comment thread mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt Outdated
@0xbrayo

0xbrayo commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

Comment thread mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt Outdated
@0xbrayo

0xbrayo commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

Every content-change event from a browser walked the event's subtree
for a WebView title (up to 2000 binder calls on the service's main
thread), including for Firefox where the lookup can never match. Skip
Firefox and look the title up at most every 500ms while it is unknown
and every 5s once found.
A rate-limited lookup could miss the title for good: if the event that
carried it was skipped and the page then went quiet, the session ended
with an empty title. When an event is skipped, schedule one lookup for
when the gate next allows it, on a fresh tree from rootInActiveWindow
while the same browser is still in front.

The timing moves into TitleLookupGate with an injected clock so its
boundaries are unit-tested.
…changes

A single global pending flag blocked the follow-up for a newly opened
browser while one for the previous browser was waiting, and the old one
then exited because the session had moved on. Track which browser the
pending follow-up is for and replace it on a switch.
@0xbrayo
0xbrayo force-pushed the perf/web-watcher-title-lookup branch from aed48e1 to d0c9bc1 Compare October 11, 2026 13:13
@0xbrayo

0xbrayo commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

Comment thread mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt Outdated
…check

A pending 5s recheck for the same browser blocked scheduling the 500ms
retry a newly opened page needs, so its title could be lost if the user
left the page before the recheck ran. Track when the pending follow-up
runs and replace it when the new one is due sooner.
@0xbrayo

0xbrayo commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

@ErikBjare
ErikBjare merged commit a4dcdf4 into ActivityWatch:master Oct 11, 2026
9 checks passed
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