Open Bug 2093286 Opened 12 days ago Updated 1 day ago

Limit how many speculation rules prefetches a document can issue, and how much data they can download

Categories

(Core :: DOM: Networking, enhancement, P2)

enhancement

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:

  1. 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.
  2. 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 queued immediate ones. CancelStalePrefetches also drops queued candidates that are no longer speculated.

  3. 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. WindowGlobalParent tracks the total; PrefetchRecordParent::OnDataAvailable cancels 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.

  4. Telemetry: a speculation_rules.prefetch_limited labeled 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.

Severity: -- → N/A
Priority: -- → P2
Whiteboard: [necko-triaged]
Assignee: nobody → smayya
See Also: → 2094473

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.

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.

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.

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.

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.

Attachment #9685603 - Attachment description: WIP: Bug 2093286 - Part 1: Tell the prefetch parent whether a candidate is immediate and split PrefetchRecordParent::Init. r?#necko-reviewers,#dom-core-reviewers → Bug 2093286 - Part 1: Tell the prefetch parent whether a candidate is immediate and split PrefetchRecordParent::Init. r?#necko-reviewers,#dom-core-reviewers
Attachment #9685604 - Attachment description: WIP: Bug 2093286 - Part 2: Limit how many speculation rules prefetches a document can have. r?#necko-reviewers,#dom-core-reviewers → Bug 2093286 - Part 2: Limit how many speculation rules prefetches a document can have. r?#necko-reviewers,#dom-core-reviewers
Attachment #9685605 - Attachment description: WIP: Bug 2093286 - Part 3: Limit how many speculation rules prefetches a document can have in flight. r?#necko-reviewers,#dom-core-reviewers → Bug 2093286 - Part 3: Limit how many speculation rules prefetches a document can have in flight. r?#necko-reviewers,#dom-core-reviewers
Attachment #9685606 - Attachment description: WIP: Bug 2093286 - Part 4: Limit how much data a document's speculation rules prefetches can receive. r?#necko-reviewers,#dom-core-reviewers → Bug 2093286 - Part 4: Limit how much data a document's speculation rules prefetches can receive. r?#necko-reviewers,#dom-core-reviewers
Attachment #9685607 - Attachment description: WIP: Bug 2093286 - Part 5: Count speculation rules prefetches affected by the per-document limits. r?#necko-reviewers,#dom-core-reviewers → Bug 2093286 - Part 5: Count speculation rules prefetches affected by the per-document limits. r?#necko-reviewers,#dom-core-reviewers
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: