Closed Bug 2093747 Opened 11 days ago Closed 3 days ago

SearchSERPTelemetry runs parent main-thread work for every HTTP response on every page, even when no search results page is tracked

Categories

(Firefox :: Search, defect)

defect

Tracking

()

RESOLVED FIXED
163 Branch
Tracking Status
firefox163 --- fixed

People

(Reporter: jesup, Assigned: jesup)

References

Details

(Keywords: perf)

Attachments

(1 external file)

ContentHandler in SearchSERPTelemetry.sys.mjs observes http-on-examine-response and http-on-examine-cached-response for the whole session. For every response, on every page, observeActivity() calls ChannelWrapper.get(channel), resolves the top browser via channel.loadInfo.browsingContext?.top.embedderElement, and then dispatches a separate main-thread runnable. Only inside that runnable does it look up whether the channel belongs to a tracked SERP (_findItemForBrowser), which for nearly all browsing finds nothing.

This runs in the parent process main thread, which is the bottleneck for request handling on busy pages (HTTP channel parents, classifier callbacks, OnStartRequest processing all run there).

Measured with the Gecko profiler on live (not recorded) page loads, optimized Linux build:

  • imgur.com cold load (~1400 channels): SearchSERPTelemetry.observeActivity was ~7% of the parent-side nsHttpChannel::OnStartRequest samples and 63 of 3201 parent main-thread samples (~2%), plus one extra main-thread runnable per response (480 observeActivity runnables in the first 3s, ~19.5ms).
  • On that page the parent main thread was 80-86% busy, and queued work there (e.g. URL classifier callbacks) was delayed by a median of 12ms and up to ~100ms, so per-response overhead directly lengthens request start times.

Suggested fix: return early from observeActivity() before ChannelWrapper.get() and the dispatch when no SERP is being tracked (TelemetryHandler._browserInfoByURL is empty), e.g. by passing a "has tracked SERPs" callback to ContentHandler alongside findItemForBrowser. Alternatively, only add the observers while at least one SERP is tracked.

Care is needed for the case where a SERP tab opens a new tab/window (the handler checks the opener tab and the previous window), but those still require a tracked SERP to exist, so an empty-map early return should not change behavior.

ContentHandler observes every HTTP response for the whole session, and for each one wrapped
the channel and dispatched a main-thread runnable before finding out whether any SERP was
tracked. Return early when none is.

Assignee: nobody → rjesup
Status: NEW → ASSIGNED
Pushed by rjesup@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/a1c4e2645b24 https://hg.mozilla.org/integration/autoland/rev/e3330906f7d5 Skip SERP telemetry response handling while no search results page is tracked r=search-reviewers,Standard8
Status: ASSIGNED → RESOLVED
Closed: 3 days ago
Resolution: --- → FIXED
Target Milestone: --- → 163 Branch
QA Whiteboard: [search][qa-triage-done-c163/b162]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: