---
title: "3. Where the speed comes from · glance"
description: "Everything here is a hypothesis until the phase 5 harness measures it. The starting facts are the black-box profile in chapter 6. glance's authors have not…"
canonical: "https://glance.avarok.net/docs/design/03-speed/"
lastmod: "2026-11-29T20:08:54Z"
tokens: 1250
---

1. [Docs](https://glance.avarok.net/docs/)
2. [Design](https://glance.avarok.net/docs/design/)

# 3\. Where the speed comes from

@avarok/glance@0.1.0·Updated 2026-11-29·2 min read·[View as markdown](https://glance.avarok.net/docs/design/03-speed/index.md)

Everything here is a hypothesis until the phase 5 harness measures it. The starting facts are the black-box profile in [chapter 6](https://glance.avarok.net/docs/design/06-reference-profile/). glance's authors have not read the reference's source, so this chapter reasons from what the reference's timer reports and what a one-pass design costs, not from its internals.

## 3.1 The mechanism

1. **Read the page once.** Phase 0 measured one walk reading 27 computed styles and a rect per element at 34 ms (MDN, 2.5k elements) and 174 ms (Wikipedia, 17k), against 262 ms and 1,935 ms for the reference's run. Every rule then reads the snapshot, which is memory, not DOM.
2. **Evaluate over a flat arena.** Integers for tags, attribute names and style values; per-node facts computed once and shared by the 70 rules; one dispatch walk instead of one selection per rule. Compiled to wasm, no garbage collection pauses, no per-node wrapper objects.
3. **Contrast without hit-testing every text node.** On the profiled pages, colour contrast alone is 50–65% of the run. glance computes the background of a text run from the snapshot's ancestor chain, and calls `elementsFromPoint` only when the run's box intersects a painted box that is not one of its ancestors (positioned, floated or transformed content). On document-like pages that is a small minority of runs.
4. **Geometry from stored boxes.** target-size and link-in-text-block compare stored rects and colours; they do no layout queries of their own.

## 3.2 Predicted numbers

| Workload                     | Reference                 | glance budget                        | Predicted            |
| ---------------------------- | ------------------------- | ------------------------------------ | -------------------- |
| Wikipedia, Citadel tags      | 1,935 ms                  | collect ≤ 200 ms + evaluate ≤ 150 ms | ≥ 5×                 |
| WHATWG parsing, Citadel tags | 1,514 ms                  | collect ≤ 120 ms + evaluate ≤ 150 ms | ≥ 5×                 |
| MDN, Citadel tags            | 262 ms                    | collect ≤ 40 ms + evaluate ≤ 30 ms   | ≥ 3×                 |
| 300-element app page         | 34 ms run (+24 ms inject) | instantiate ≤ 8 ms + run ≤ 10 ms     | ≈ 2× (least certain) |

The headline workload is the large documentation page. Its threshold to ship is 2× (REFRESH.md phase 5 gate).

## 3.3 Risks

- **Correctness over speed.** A rule that agrees with the reference only most of the time is worthless as a drop-in. The differential suite ([chapter 4](https://glance.avarok.net/docs/design/04-proof/)) gates every rule before its speed counts.
- **Paint order.** CSS painting order (CSS 2.1 Appendix E, stacking contexts) is hard to reproduce fully from computed styles. The fallback is the browser's own hit test, so the cost of being unsure is speed, never a wrong answer.
- **Style reads.** `getComputedStyle` forces a style recalculation once and then costs a few microseconds per property. The collector reads only the properties some enabled rule needs, and skips reading styles under `display: none` roots beyond what hiddenness needs.
- **Wasm size.** The module is embedded in the injected script, so its size is part of injection time. Budget: the injected script no larger than the reference's `axe.min.js`.

## 3.4 What will not be faster

- Pages dominated by custom checks written in JS through `configure`: those run outside the core.
- Cross-origin frames: messaging between frames is the same cost for both.

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@id": "https://thomaspbraun.com/#person",
      "@type": "Person",
      "name": "Thomas Braun",
      "sameAs": [
        "https://github.com/tbraun96",
        "https://x.com/tbraun96"
      ],
      "url": "https://thomaspbraun.com",
      "worksFor": {
        "@type": "Organization",
        "name": "Avarok",
        "url": "https://avarok.net"
      }
    },
    {
      "@id": "https://glance.avarok.net/docs/design/03-speed/",
      "@type": "WebPage",
      "author": {
        "@id": "https://thomaspbraun.com/#person"
      },
      "dateModified": "2026-11-29T20:08:54Z",
      "description": "Everything here is a hypothesis until the phase 5 harness measures it. The starting facts are the black-box profile in chapter 6. glance's authors have not…",
      "inLanguage": "en",
      "isPartOf": {
        "@id": "https://glance.avarok.net/#website",
        "@type": "WebSite",
        "name": "glance",
        "url": "https://glance.avarok.net/"
      },
      "name": "3. Where the speed comes from · glance",
      "url": "https://glance.avarok.net/docs/design/03-speed/"
    }
  ]
}
```
