Limit how many speculation rules prefetches a document can issue, and how much data they can download
Categories
(Core :: DOM: Networking, enhancement, P2)
Tracking
()
People
(Reporter: smayya, Assigned: smayya)
References
(Blocks 1 open bug)
Details
(Whiteboard: [necko-triaged])
Attachments
(5 external files)
A document can currently start any number of speculation rules prefetches, all in parallel, with no cap on the total data downloaded. A page with many links and an immediate document rule prefetches every one of them at once. dom.speculation_rules.max_records_per_document was meant to cap this, but nothing reads it.
Proposed limits, all per document and controlled by prefs:
-
Eagerness budgets (counting only successfully completed records, as Chrome does):
immediate: 50 (dom.speculation_rules.max_immediate_prefetches). Candidates past the budget are dropped.eager/moderate/conservative, sharing one budget: 5 (dom.speculation_rules.max_non_immediate_prefetches). When it is full, the oldest completed non-immediate record is evicted (FIFO) to make room for the new one. In-flight prefetches are never evicted.- These replace the unused
dom.speculation_rules.max_records_per_document.
-
In-flight limit: at most 2 prefetches downloading at once (
dom.speculation_rules.max_inflight_prefetches_per_document). Further candidates are queued and started as slots free up; queued non-immediate candidates start before queuedimmediateones.CancelStalePrefetchesalso drops queued candidates that are no longer speculated. -
Total data cap: 20 MB of prefetch data received per document over its lifetime (
dom.speculation_rules.max_total_bytes_per_document), enforced in the parent.WindowGlobalParenttracks the total;PrefetchRecordParent::OnDataAvailablecancels the fetch that goes over it, and new records are rejected once it is used up. The existing 5 MB cap per record (dom.speculation_rules.max_body_bytes) stays. -
Telemetry: a
speculation_rules.prefetch_limitedlabeled counter recording dropped, evicted, queued and size-capped prefetches.
For comparison, Chrome (PrefetchDocumentManager, PrefetchScheduler) allows 50 immediate and 2 non-immediate completed prefetches per page with FIFO eviction for the latter, and 3 prefetches in flight at once across the whole profile. It has no total data cap.
| Assignee | ||
Updated•12 days ago
|
| Assignee | ||
Updated•12 days ago
|
| Assignee | ||
Comment 1•10 days ago
|
||
The prefetch limits will be enforced in the parent, which has to know whether
a record is immediate, since immediate and non-immediate prefetches get
separate per-document budgets, and has to be able to start a record's fetch
after Init.
| Assignee | ||
Comment 2•10 days ago
|
||
Immediate and non-immediate prefetches get separate per-document budgets,
enforced in the parent. A record counts while in flight and until it
expires. When the immediate budget is full, further immediate candidates are
not prefetched. When the non-immediate budget is full, the oldest completed
record is evicted so the newest candidate can be prefetched.
A completed record is now canceled when it expires, rather than kept until a
navigation finds it expired, so it stops counting against its budget and
its cache entry is released.
| Assignee | ||
Comment 3•10 days ago
|
||
A document can now have only a limited number of prefetches in flight at
once (dom.speculation_rules.max_inflight_prefetches_per_document, 3 by
default). Further records are queued in the parent, and started when an
in-flight one completes, fails or is canceled. Non-immediate records are
started before immediate ones, since the user is pointing at those links.
A queued record is checked against its budget when it leaves the queue, and
a navigation never waits for a queued record.
| Assignee | ||
Comment 4•10 days ago
|
||
The response bytes a document's prefetches receive are added up over the
document's lifetime (dom.speculation_rules.max_total_bytes_per_document,
20 MB by default), including those of records that were later used,
evicted, expired or canceled. The fetch that goes over the total is
canceled, and once it is used up no further prefetch is started for the
document. The 5 MB limit per record stays.
| Assignee | ||
Comment 5•10 days ago
|
||
speculation_rules.prefetch_limited counts, once per record, a prefetch
that waits for an in-flight slot, an immediate one that is rejected
because its budget is full, one that is evicted, and one that is rejected
or canceled because the document's prefetches received as much data as
allowed.
Updated•10 days ago
|
Updated•10 days ago
|
Updated•8 days ago
|
Updated•5 days ago
|
Updated•5 days ago
|
Description
•