Highlight Timings
Per-layer timing breakdown for a single highlight call.
Each field is a Duration measured via measureTimedValue at each pipeline stage. All fields are always populated - themeParse is non-zero only on the first call for a given HighlightTheme (the CSS parse is lazy and cached; subsequent calls report Duration.ZERO).
Pipeline stages
| Stage | Description |
|---|---|
| jsBridge | evaluateJavascript() round-trip into WebView running highlight.js |
| jsonUnescape | unescapeJsString() pass over the returned JSON string |
| htmlParse | HTML parsing into a node tree and building the AnnotatedString |
| themeParse | Theme CSS parsing - first-use only; Duration.ZERO on cache hits |
| total | End-to-end time for the full highlight call |
Usage
engine.highlight(code, "kotlin", theme).onSuccess { result ->
val t = result.timings
println("JS bridge: ${t.jsBridge}") // e.g. "45ms"
println("JSON unescape:${t.jsonUnescape}") // e.g. "1ms"
println("HTML parse: ${t.htmlParse}") // e.g. "3ms"
println("Theme parse: ${t.themeParse}") // non-zero on first call only
println("Total: ${t.total}") // full elapsed wall-clock time
// Or get raw numbers:
val jsBridgeMs = t.jsBridge.inWholeMilliseconds
val htmlParseNs = t.htmlParse.inWholeNanoseconds
}Constructors
Properties
Time for parsing the highlight.js HTML output and building the androidx.compose.ui.text.AnnotatedString in a single SAX-style pass.
Time for unescapeJsString - the character-by-character pass that strips JSON encoding from the string returned by the JS engine.
Time for theme CSS parsing on first use of a HighlightTheme. Duration.ZERO on all subsequent calls for the same theme instance because the color map is lazily computed and cached.
Full elapsed wall-clock time for the HighlightEngine.highlight call. Measured end-to-end and includes overhead not captured by the individual stage fields (WebView initialization wait, mutex queuing, dispatcher hops). Use this for overall latency; use the individual stage fields to identify which layer is the bottleneck. Equals HighlightResult.durationMs converted to Duration.