skip to content

Frame Time & Memory

At 60 Hz a frame has about 16 ms and at 120 Hz about 8 ms, so main-thread work must stay small while memory stays under the OS kill line. Interviewers probe jank and low-memory kills.

on this pageshow

explore

questions

6

In a phone photo-editing app, how long does each frame have at 60 Hz and 120 Hz, and what happens when the app misses it?

level: juniorimportance: must knowfreq 58%

answer

  1. one refresh interval, not one second
  2. 1000 divided by the refresh rate
  3. the app gets only a slice
  4. late by a whole interval, not 1 ms
  5. budget for the fastest display shipped

basics

~20 s

About 16.7 ms at 60 Hz and 8.3 ms at 120 Hz, of which the app's own work gets only part. A missed deadline is not a slightly late frame: the old picture stays a whole refresh longer.

solid answer

~50 s

The deadline is one refresh interval: 1000 ms / 60 is about **16.7 ms**, 1000 ms / 120 is about **8.3 ms** (90 Hz gives about 11 ms). Inside it the main thread must take the input event, run the app's code, lay out what changed and hand the frame to the rendering stage, and other queued main-thread work competes for the same slot, so the app's share is smaller still; one platform's guidance says main-thread work under about 5 ms per update usually lands in time. Missing by 1 ms costs a full interval: the display shows the previous frame again, so the slider thumb or the list visibly jumps. A 120 Hz screen typically runs at its top rate while the user touches it (one platform documents this), so work that just fits at 60 Hz can miss every frame at 120 Hz. Budget for the fastest display you ship.

go deeper

for a junior

Recall the arithmetic: 1000 divided by the refresh rate gives about 16.7 ms at 60 Hz and 8.3 ms at 120 Hz, and a missed frame costs a whole interval.

for a middle

Explain what shares the frame: input handling, the app's code, layout and the hand-off to rendering, which is why the app's own slice at 120 Hz is only a few milliseconds.

for a senior

Show that you budget for the highest refresh rate you ship and the slowest phone with that display, and name concrete gesture-time offenders such as full-resolution passes, decodes and disk writes.

for a principal

Discuss how one per-frame budget is agreed across 60 Hz and 120 Hz devices and held by every feature team, instead of tuning screens one by one after users complain.

## The deadline is one refresh interval A phone's display redraws at a fixed rate while something moves on it. Each redraw is a **refresh**, and the time between two refreshes is the **frame deadline**: the next picture has to be ready by then, or the display shows the old one again. | Display rate | Interval (1000 ms / rate) | Frames in one second of motion | |---|---|---| | 60 Hz | about 16.7 ms | 60 | | 90 Hz | about 11 ms | 90 | | 120 Hz | about 8.3 ms | 120 | Two facts turn this arithmetic into a design input rather than trivia: - **The fast rate is used exactly when it hurts.** One platform's documentation says its displays update at their maximum rate during user interaction and may slow down only when nothing new is shown. Dragging a slider or scrolling a layer list is interaction, so a 120 Hz phone holds the app to 8.3 ms then. - **The budget is per frame, not per second.** A frame that finished early buys nothing for the next one. Ten cheap frames and one 40 ms frame still produce a visible stutter. ## What shares the frame The app's own code does not get the whole interval. Within one frame the **main thread** (the thread that handles input and updates the UI) has to: 1. receive the input event (the finger moved, so the slider value changed); 2. run the app's handler and update its state; 3. measure and lay out whatever changed; 4. record the drawing and hand the frame to the rendering stage, which turns it into pixels against its own deadline. Anything else queued on the main thread — a network result being applied, a timer, a logging call — competes for the same slot. One platform's guidance gives the order of magnitude: main-thread work for a screen update that stays under **about 5 ms** is usually ready in time, and anything longer needs checking against the specific devices and refresh rates the app supports. That is a rule of thumb from one platform, not a law, but it shows that at 120 Hz the app's slice is a few milliseconds. ## What a miss looks like When the main thread is still busy at the deadline, the new frame is not ready and the display shows the previous picture for another whole interval. The frame does not arrive 1 ms late; it arrives a full interval late — 16.7 ms at 60 Hz. One platform drops the late frame outright; the other may still show it, one refresh late. Either way the motion jumps: the slider thumb skips ahead, the list lurches. This is a **slow** or **dropped frame**, and users call the result **jank**. Very long frames form a separate category. One platform calls a frame that takes longer than **700 ms** to render a **frozen frame**, because the app looks stuck. And when the main thread cannot answer a tap for seconds, that is a **hang**, which is captured and triaged like a crash rather than counted as a smoothness problem. ## Work that breaks the deadline during a gesture In a photo-editing app the usual offenders while a slider moves are: - a filter pass over the full-resolution photo, tens of millions of pixels, which no phone finishes in a few milliseconds; - decoding an image from its compressed file; - disk or database reads and writes, such as saving the undo history; - parsing a large document, such as a preset file or a JSON response; - waiting synchronously for a result from another thread; - many small jobs posted to the main thread "asynchronously" — they still run on the main thread, in the middle of the gesture. The remedy is the same for all of them: the main thread only applies finished results, and the work runs elsewhere and on less data. How a live preview achieves that is a design question in its own right. ## Budget for the fastest display you ship on Work that just fits at 60 Hz can miss every frame at 120 Hz, because the interval halves while the work does not. A team therefore sets its per-frame budget from the highest refresh rate it supports and checks it on the slowest phone that has such a display. Background threads are not free either: they share CPU cores with the main thread, and one platform warns that too many threads leave each of them, the main thread included, less time on a core. The frame deadline is a fixed number; everything the app does during motion has to fit inside a fraction of it.

  • Why does the first frame of a newly opened editor screen get more latitude than frames during a slider drag?
    The first frame must build, lay out and draw the whole screen from scratch, so it commonly exceeds one interval; one platform calls that normal and treats a frame as frozen only past 700 ms. During a drag nothing is built from scratch, so every frame is held to the refresh deadline.
  • If the heavy work moves to a background thread, is it free as far as frames are concerned?
    No. Background threads share CPU cores with the main thread, so too many of them leave the main thread less time on a core; each finished result still costs main-thread time to apply; and full-resolution buffers they allocate count against the app's memory. Moving work off the main thread protects the deadline; it does not remove the cost.

A frame deadline is a train that leaves every 8 minutes. Reach the platform one minute late and you do not arrive one minute late: you wait for the next train and arrive a whole interval late, which is exactly what a missed frame costs.

  • Every phone gives an app 16 ms per frame, whatever its refresh rate
  • Missing a frame deadline by 1 ms delays that frame by only 1 ms
  • The app's own code gets the whole refresh interval to itself
  • Work posted asynchronously to the main thread cannot cause a dropped frame
  • A 120 Hz display only matters for games, not for sliders and scrolling
open as a page

Why does the OS end a phone photo editor while its user is in the camera, and how should the editor avoid losing the edit?

level: middleimportance: must knowfreq 55%

basics

~20 s

The camera creates memory pressure, and the OS reclaims background apps first, a large editor early, without running its code. Save each edit's operations as it commits, and drop rebuildable pixels when leaving the screen.

open as a page

In a phone photo-editing app, a live filter preview drops frames while a slider drags over a 48-megapixel photo; how should the preview be designed?

level: middleimportance: must knowfreq 54%

basics

~20 s

Preview from a screen-sized proxy, not the 48-megapixel original, rendered off the main thread with only the newest slider value; the main thread just swaps in finished images, and the full-resolution render runs after release.

open as a page

On a 3 GB phone, how would you budget memory for a photo-editing session with layered edits and a 30-step undo history on a 48-megapixel photo?

level: seniorimportance: should knowfreq 48%

basics

~10 s

Count decoded pixels: a 48-megapixel image at four bytes a pixel is about 192 MB. Hold one full-resolution buffer at most, layers as parameters, screen-sized previews, a tiled export, and undo as operations.

open as a page

In a phone photo-editing app, memory grows about 200 MB each time the editor screen opens and closes until the OS ends it; what keeps a closed screen alive, and how do you tell a leak from a cache?

level: seniorimportance: should knowfreq 50%

basics

~20 s

Something long-lived still references the closed screen: a listener never removed, a task or timer that captured it, a singleton or static map holding it. A cache plateaus at its bound; a leak climbs every open-close cycle.

open as a page

In a phone photo-editing app, why can an average frame rate of 58 fps hide the jank users report after a release, and what should the app measure instead?

level: seniorimportance: should knowfreq 46%

basics

~10 s

An average dilutes a few long stalls among thousands of on-time frames. Measure, during motion only, the share of frames that missed this device's deadline and any frame long enough to look frozen.

open as a page