liveBook · Manning

Prefetch

As explained in Latency

The proactive retrieval of anticipated data before it is explicitly requested.

Prefetching retrieves data before an application requests it. The aim is to overlap a slow read with other work so the data is ready when needed. It hides access latency rather than making the read itself faster. Unlike replication or caching, it need not rely on managing multiple copies of data. section 11.2

Fetch during authentication

When a user logs in, fetch likely user-specific data in parallel with authentication. If the prediction is right, the application can respond immediately after login instead of starting those reads then. section 11.1

Choose a predictor that fits the access pattern:

  • Pattern-based prefetching uses regular access: successive records, nearby records, or records at a fixed stride. It can exploit physical proximity without understanding what the user intends. section 11.2.1
  • Semantic prefetching uses current actions or business logic to anticipate an application-specific next request. section 11.2
  • Machine learning can identify less obvious relationships between accesses and adapt predictions as workloads change. section 11.2

For sequential processing, request upcoming elements while processing the current one. If the dataset exceeds memory, keep a resident prefetch window and tune its size so upcoming data is available without fetching too far ahead. section 11.2.1

Figure 11.1 With sequential prefetching, we predict that successive data elements relative to the one we’re accessing will be needed in the future. In this example, we access the first data element and, therefore, predict that the next data elements will also be needed.

The diagram shows an access to the first element triggering retrieval of the next two before they are processed. section 11.2.1

Start with a read whose latency matters, predict when and what to fetch, then initiate the read early enough for its result to be useful. Check the cost of wrong predictions: fetching unwanted data wastes resources, while fetching the wrong data leaves the needed read on the critical path. An overly conservative strategy misses opportunities; an overly aggressive one can worsen latency. section 11.1 section 11.2

How Latency covers it

How deep it goes
Explains prediction strategies, a sequential prefetch window, and failure costs, but provides no application implementation code.
Examples
Illustrates the idea with login-time user-data retrieval and sequential file processing.
What it assumes
Requires recognizing data-access latency and access patterns; defines predictive techniques through a basic three-step procedure.
What you can do after
Operate/configure it by choosing an access predictor and tuning a resident window while accounting for wasted reads.
How it connects
Connects prefetching to caching, replication, speculative execution, and memory access patterns.

Also explained in

Compare how 3 books explain prefetch →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Latency. The section links point to the parts of the book it draws on.