Skip to content

Hyperlink: store the special-URL catalog as typed rows #776

Closed

Description

@HMarzban

Part of #769. Small; ship with other hyperlink work. Touches the same file as #774 site 3.

Summary

The special-URL catalog (extensions/extension-hyperlink/src/utils/specialUrls.ts:66-170) is seven Record objects joined by a spread. Typed rows carry the same data in fewer bytes. Every user of the extension pays the catalog. Behaviour and the public SpecialUrlType union stay the same.

Review numbers (2026-11-12, prototype; this issue takes its own before and after)

Row Today Typed rows
A StarterKit app pays (min / gzip) 70,854 / 25,213 B −1,303 / −97 B
The webapp-like app pays 54,947 / 19,144 B −1,303 / −111 B

Fix

  1. Replace the seven objects and the spread with toEntries([...] as const satisfies readonly Row[]), where type Row = readonly [string, SpecialUrlType, string, SpecialUrlInfo['category']].
  2. Iterate the entry arrays, not Object.entries, and keep today's lookup order.
  3. Keep the SpecialUrlType union (lines 7-51) and the SpecialUrlInfo text byte-identical. Both are public: src/utils/index.ts:11 and docs/api.md:233; the webapp's specialUrlIcon.ts:11 uses Record<SpecialUrlType, ...>.
  4. Use satisfies, not a cast. In the review, a typo (emial) failed tsc with TS2820 in the satisfies form. In the cast form it passed tsc, and only 2 of 71 tests caught it.

Benchmark

Field Value
Metric Package bench byte rows.
Before 70,854 / 25,213 B (StarterKit app, main, 2026-11-12).
After not measured yet
Confounds #774 (site 3 lives here).
Condition esbuild minify, ESM, browser, Bun zlib level 9, exact.
How to run NODE_ENV=production bun scripts/bench/run.ts --ref <commit before this issue>
Pass rule At least −1,000 B min for a StarterKit app; behaviour unchanged; speed inside the control band.
Guard The UX contract below.
Owner Agent in the repo.
Claim None for users (too small to promote). Note it as Internal.

UX contract

  • An equivalence check over every catalog key and at least 161 inputs: the same icon, label, category and order as today, 0 differences. When two rows match one URL, the same row wins.
  • dist/index.d.ts byte-identical, so the union is unchanged.
  • Pad: special-URL icons (mail, Zoom, GitHub and so on) look as before.

Acceptance checks

  • bun test src/utils/__tests__/specialUrls.test.ts src/utils/__tests__/validateURL.test.ts: all pass (166 today).
  • A one-row typo fails tsc (sabotage).
  • bun run test:unit, typecheck, lint.
  • Before and after bench posted here. CHANGELOG Internal line.

Out of scope

  • Widening SpecialUrlType to string.

Activity

  1. added this to the v2.3.8 milestone on Nov 12, 2026
  2. self-assigned this
    on Nov 12, 2026
  3. added
    Performance
    on Nov 12, 2026
  4. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    Measured (2026-11-12, working tree, not committed yet)

    Change: src/utils/specialUrls.ts stores the catalog as toEntries([...] as const satisfies readonly Row[]) rows and loops over the entry arrays. The SpecialUrlType union and SpecialUrlInfo are unchanged.

    Package bench, base = a copy of src/ with #770 and #772, head = that plus this change:

    Metric base head Change
    Bytes: npm dist/index.js (min / gz) 57,343 / 20,588 56,040 / 20,484 -1,303 / -104
    Bytes: a StarterKit app pays (min / gz) 71,049 / 25,273 69,746 / 25,177 -1,303 / -96
    Bytes: normalizeHref-only import (min / gz) 368,225 / 121,463 366,922 / 121,319 -1,303 / -144
    Behaviour: all cases 18/18 18/18 0
    Behaviour: strip 10/10 10/10
    Behaviour: undo 2/2 2/2
    Behaviour: keep 4/4 4/4
    Behaviour: href 2/2 2/2
    Speed: pasteText2000 (ms) 454.253 462.076 +2% · control -0%
    Speed: boldAll2000 (ms) 338.131 342.914 +1% · control +1%
    Speed: typeEnd2000 (µs/key) 152.164 149.86 -2% · control -1%
    Speed: pasteOverSelection250k (ms) 20.796 20.909 +1% · control +3%
    Speed: boldPartOfLink (ms) 0.096 0.096 +0% · control +31%
    Speed: mount1000Links (ms) 23.436 23.43 -0% · control +0%

    jsdom on Bun 1.4.4, darwin arm64, 9 rounds. boldPartOfLink is about 0.1 ms, so its percentages are timer noise (the control copy moved +31 %).

    Checks run:

    • Equivalence: getSpecialUrlInfo before and after over all 63 catalog keys and 161 derived inputs: 0 differences.
    • specialUrls.test.ts + validateURL.test.ts: 166 / 166.
    • Sabotage: the typo emial in one row fails tsc with TS2820.
    • bun run typecheck, ESLint and Prettier clean. CHANGELOG Internal line.

    Still owed: the full package Cypress suite (runs once with #772 and #773), a glance at special-URL icons on the pad, the commit.

  5. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    Pad check (local dev-local, 2026-11-12)

    On a local pad with this change built in: a mailto: link shows its special-URL icon, and github.com links show the GitHub icon, as before.

  6. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    Committed

    c9cd2c98a on main, 2026-11-12, not pushed yet. One commit holds #770, #772, #773 and #776 together, by the maintainer's choice, so it cites each with Refs, and none closes on push. It is the same code the measured comments above describe.

    Open before this issue closes:

    • Production glance after deploy: special-URL icons look as before.
  7. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Production check, 2026-11-16. docs.plus at b7888dce1 (deployed 2026-11-15). Chrome on macOS, signed in. One scratch pad, never /demo. Each result was read from the editor DOM after the action. n = 1.

    A pad with a mailto: link and a github.com link shows both special-URL icons: the mail glyph (hyperlink-icon) and the GitHub icon from the icon route. The per-module specialUrls d.ts emit is identical (1,243 B), unit tests are 474/474 and Cypress 289/289 (#770, #773). The change is c9cd2c98a, live since 3d90636a9 and still in b7888dce1. Release credit v2.3.8. Closing as done.

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

Metadata

Metadata

Assignees

Labels

ExtensionPerformanceRefactor

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions