27.9KB language-agnostic1 WebGPU syntax highlighter

import { parse } from 'gpu-lexer'

const spans = await parse('source code')
// {
//   type: 'plain' | 'comment' | 'string' | 'number' | 'keyword' | 'type' | 'function' | 'constant' | 'operator'
//   start: number
//   end: number
// }[]

gpu-lexer splits source code into simple parts—words, whitespace, newlines, and symbols. Then a tiny WebGPU model combines local and whole-file context to label each part. It is designed for any language: instead of choosing a grammar, it guesses each part's type from the surrounding source, even when it never saw that language or syntax during training. Adjacent labels become the syntax spans returned to your code.

This is an experiment, not a grammar-equivalent highlighter (see the agreement chart below). The chart measures agreement with Shiki—not objective correctness—and results may vary on unseen languages or real-world code.

Highlight 10× three.min.jswarmed browser time · lower is better
Highlights75.3ms
Sugar High820.0ms
Prism.js1.24s
Highlight.js1.36s
Starry Night11.4s
Shiki30.4s

Median of three samples on October 22, 2026. Each sample ran in a fresh dedicated worker and timed one call after one warm-up call; the engine order rotated between rounds. The input was 10 concatenated copies of three.min.js (5.56M characters). MacBook Pro, Apple M4 Pro, 20-core GPU, 24GB, macOS 26.7.1, headless Chrome 156. DOM rendering was excluded. gpu-lexer returned spans, Highlights and Shiki returned themed tokens, Starry Night returned a HAST tree, while Sugar High, Prism.js, and Highlight.js returned highlighted HTML. Highlights 0.2.0, Sugar High 2.3.1, Prism.js 1.30.0, Highlight.js 11.12.0, Starry Night 3.11.0, and Shiki 4.4.3.

Loaded library sizeruntime + selected language coverage · lower is better
Sugar High (major 6 web languages)5.4KB
Prism.js (major 6 web languages)8.6KB
Sugar High (all 29 languages)8.8KB
Highlight.js (major 6 web languages)14.9KB
Highlights (all 80 languages)95.9KB
Prism.js (all 297 languages)162.1KB
Starry Night (major 6 web languages)185.3KB
Shiki (major 6 web languages)213.9KB
Highlight.js (all 193 languages)240.4KB
Shiki (all 242 grammars)991.5KB
Starry Night (all 710 grammars)1.46MB

Minified and Brotli-compressed browser bundles, all measured on October 22, 2026. Major web includes javascript, typescript, css, html, json, and markdown. gpu-lexer uses the same bundle for every language. Starry Night totals include its Oniguruma WASM payload. Highlights ships every lexer in one WebAssembly module; themes are excluded.

Top-25 weighted agreementpopularity-weighted agreement with Shiki · higher is better
Shiki100%
Prism.js84.05%
Sugar High73.61%
Starry Night72.25%
Highlight.js70.12%

Shiki is the 100% normalization reference. Each library's token names are mapped to the same nine classes: plain, comment, string, number, keyword, type, function, constant, and operator. Scores compare non-whitespace source parts across 1,103 held-out files in the GitHub Innovation Graph top 25 for 2026-Q1, weighted by each language's pusher count. Unsupported languages score zero; corpus size does not affect the weights.

[ live demos ]

75 languages