HighlightTimings

data class HighlightTimings(val jsBridge: Duration, val jsonUnescape: Duration, val htmlParse: Duration, val treeWalk: Duration, val themeParse: Duration, val total: Duration)

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

StageDescription
jsBridgeevaluateJavascript() round-trip into WebView running highlight.js
jsonUnescapeunescapeJsString() pass over the returned JSON string
htmlParseJsoup.parseBodyFragment() - HTML to DOM
treeWalkDOM node walk + SpanStyle lookup from theme color map
themeParseThemeParser.parse() - first-use only; Duration.ZERO on cache hits
totalEnd-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("Tree walk: ${t.treeWalk}") // e.g. "2ms"
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 treeWalkNs = t.treeWalk.inWholeNanoseconds
}

Constructors

Link copied to clipboard
constructor(jsBridge: Duration, jsonUnescape: Duration, htmlParse: Duration, treeWalk: Duration, themeParse: Duration, total: Duration)

Properties

Link copied to clipboard

Time for Jsoup.parseBodyFragment() - parsing the highlight.js HTML output into a DOM tree.

Link copied to clipboard

Time for the evaluateJavascript() round-trip - from immediately before the call to when the JS result callback fires. Excludes WebView warm-up and mutex-wait time.

Link copied to clipboard

Time for unescapeJsString - the character-by-character pass that strips JSON encoding from the string returned by the JS engine.

Link copied to clipboard

Time for ThemeParser.parse - 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.

Link copied to clipboard

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.

Link copied to clipboard

Time for the DOM tree walk and androidx.compose.ui.text.SpanStyle application loop that builds the androidx.compose.ui.text.AnnotatedString.