Skip to content

leaf-dev bench times each Firefox input from a quiet main thread and splits its time by owner #6480

Open

Description

@max-sixty

Two gaps in leaf-dev bench misled the Firefox budget work in #6479.

A fixed wait after preparing an input. Before timing an input, the bench prepares the page for it and then waits a fixed 600 ms (tab.quiet, bench.py:987, called after each preparation, such as halfway's at line 1083). On document at size 512, halfway jumps to the middle of the listing, and colouring that landing takes about 100 ms of main thread over the next two wheel steps (#6482). Some rounds time that burst as wheel cost: in Firefox, 2 of 7 rounds of main read 17.6 and 18.2 ms per wheel step, against 10.3 to 12.2 for the rest, and a profile's window averaged it in as 3.1 ms of syntax colour per step that no steady step spends. The lowest-of-3 table hides it only while one round misses the burst.

The CPU pass already waits for the main thread to go quiet after the load (idle_rate in cpu_pass: two half seconds in a row under QUIET_MS). Waiting the same way after each preparation, instead of the fixed 600 ms, would time only the input, as root AGENTS.md, "Wait for the event that ends the work", asks.

No Firefox profile split. --profile reads V8 only, so naming what took Firefox's time took a hand-written script over a Gecko shutdown profile, recorded with the variables the bench.py header names. The script finds each content process's GeckoMain thread, groups its DOMEvent markers of one type into an input's window (from the event to 50 ms after the last wheel, or 60 ms after the last keystroke), and sums each sample's threadCPUDelta (µs) by owner: the first rule matching its stack, after geometry reads and Gecko's Layout category. The raw shutdown profile keeps each table as a schema and rows that may be short, nests content processes under processes, and gives each process its own time base. Splitting by owner per input in bench would make the next Firefox question one command.

The script used in #6479 (owners by input window, first two wheel steps dropped)
"""Split each input window's main-thread CPU by owner, for the chart."""
import json, re, sys
from collections import Counter

def col(r, i): return r[i] if i is not None and i < len(r) else None
p = json.load(open(sys.argv[1]))
def threads(p):
    for t in p.get("threads", []): yield p.get("meta", {}), t
    for s in p.get("processes", []): yield from threads(s)
RULES = [
    ("Reading place capture", r"recordPlaces|capturePlace"),
    ("Chrome repaint frame", r"repaint\.js"),
    ("Key dispatch", r"keyboard/dispatch\.js"),
    ("Text field editor", r"codemirror|text-field\.js|field-editor\.js"),
    ("Syntax colour", r"lf-text-document|syntax\.esm|syntax-tokens|Highlight\.add"),
]
GEO = re.compile(r"^(Element\.getBoundingClientRect|Element\.getClientRects|Range\.getClientRects|Range\.getBoundingClientRect|Window\.getComputedStyle|get (Element|HTMLElement)\.(client|offset|scroll)\w+|Document\.caretPositionFromPoint|Document\.elementsFromPoint|Document\.elementFromPoint|get CSSStyleProperties\.\w+|CSSStyleDeclaration\.getPropertyValue|Element\.checkVisibility)$")
out = {}
for meta, t in threads(p):
    if t.get("name") != "GeckoMain" or t.get("processType") != "tab": continue
    S = t["stringTable"]; ms, md = t["markers"]["schema"], t["markers"]["data"]
    cats = [c["name"] for c in meta.get("categories", [])]
    for ev, after in (("wheel", 50), ("keydown", 60)):
        evs = sorted(col(r, ms["startTime"]) for r in md if isinstance(col(r, ms["data"]), dict) and col(r, ms["data"]).get("type") == "DOMEvent" and col(r, ms["data"]).get("eventType") == ev)
        groups = []
        for e in evs:
            if groups and e - groups[-1][-1] < 1000: groups[-1].append(e)
            else: groups.append([e])
        for g in groups:
            if len(g) < 5 or g[0] < 100: continue
            skip = 2 if ev == "wheel" else 0; lo, hi = g[skip], g[-1] + after
            ss, sd = t["samples"]["schema"], t["samples"]["data"]
            st, sdat = t["stackTable"]["schema"], t["stackTable"]["data"]
            fs, fd = t["frameTable"]["schema"], t["frameTable"]["data"]
            c = Counter()
            for r in sd:
                tm = col(r, ss["time"])
                if not (lo <= tm <= hi): continue
                d = col(r, ss["threadCPUDelta"]) or 0
                s = col(r, ss["stack"])
                names, cat = [], None
                while s is not None:
                    f = col(sdat[s], st["frame"])
                    names.append(S[col(fd[f], fs["location"])])
                    if cat is None and col(fd[f], fs.get("category")) is not None:
                        cat = cats[col(fd[f], fs.get("category"))]
                    s = col(sdat[s], st["prefix"])
                joined = " | ".join(names)
                if cat == "Layout" or any(GEO.match(n) for n in names):
                    c["Geometry reads, style and layout"] += d
                    continue
                for label, rx in RULES:
                    if re.search(rx, joined):
                        c[label] += d; break
                else:
                    if cat == "Idle" or not names: c["(idle)"] += d
                    elif re.search(r"[(/](runtime|vendor|packages)/", joined): c["Other Leaf script"] += d
                    elif cat == "Layout": c["Style and layout"] += d
                    elif cat == "Graphics": c["Display list and paint"] += d
                    elif cat == "GC / CC": c["GC"] += d
                    else: c["Other browser work"] += d
            n = len(g) - skip
            key = f"{ev} pid{meta.get('pid','?')} t{lo:.0f}"
            out[key] = {k: round(v / 1000 / n, 2) for k, v in c.most_common()}
for k, v in out.items():
    print(k, json.dumps(v))

The full scripts and the profile they read are in ~/.tmp/leaf.measured-geometry-owner/geo/ on Max's Mac (gecko.py also lists the innermost Leaf functions per window).

Max paused this work on 18 November 2026; it waits on his go-ahead.

This was written by Claude Code on behalf of max-sixty

Activity

  1. added
    backlog
    on Nov 19, 2026
  2. self-assigned this
    on Nov 19, 2026
  3. added
    next
    dev-velocity
    on Nov 19, 2026
  4. max-sixty commented on Nov 25, 2026

    @max-sixty
    OwnerAuthor

    Max's answer for this and #6479, 24 November:

    extend these a bit, maybe give it 12ms, and say that we can look again at this when other architectural changes have settled, in a week or so

    #7100 raises the keystroke and wheel-step budget to 12 ms. This issue stays open, assigned to Max, for that second look around 1 December.

    This was written by Claude Code on behalf of max-sixty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backlogdev-velocitynext

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions