liveBook · Manning

Thread

As explained in Fast by Default

A background thread is an execution thread that performs work independently of the primary interface thread.

A background thread performs work independently of the primary interface thread. Keeping expensive work away from the main thread helps the interface remain responsive during scrolling, input, and rendering. section 7.3.1

Use background threads for data processing, network-response handling, image decoding, storage, and other CPU- or I/O-heavy tasks. Keep drawing and arranging interface elements on the main thread, then return results for display. A profiler exposes the boundary: if application calculations run on the main thread during scrolling, move them off it. section 7.3.1 section 1.3.1

Image decoding during scrolling

An application that decodes images while the user scrolls can spend 1.4 seconds on work that blocks interface progress. Profile activity by thread, locate the decoding call, move decoding to a background thread, and keep only the resulting display update on the main thread. section 7.3.1

Figure 7.5 An example call tree showing where time is spent. The top rows are system code you cannot change. Keep expanding until you reach your own functions at the bottom, which is where you focus your attention to improve performance.

Expand the call tree from system code to application functions, then use thread placement to identify work that should leave the main thread. section 7.3.1

How Fast by Default covers it

How deep it goes
Explains workload placement and profiling signals, but stops short of specifying thread APIs or synchronization mechanics.
Examples
Uses scrolling with 1.4 seconds of image decoding and profiler call trees to demonstrate workload relocation.
What it assumes
Assumes familiarity with interface rendering, user input, network or storage work, and execution threads.
What you can do after
Diagnose thread-related responsiveness problems with profilers and relocate non-interface work off the main thread.
How it connects
Connects user input, rendering, image decoding, network requests, data processing, and performance profiling.

Also explained in

Compare how 17 books explain thread →

Related concepts

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