Theme.applyStyleToString DEBUG print fires per token for legitimately-unstyled classes
Location: Sources/Highlighter/Theme.swift:209
#if DEBUG
print("WARNING MISSING STYLE in \(self.name): \(aStyle)")
#endif
Problem
This fires once per token whose class isn't in the theme's CSS. But many highlight.js themes intentionally omit classes they want to inherit the default text color — that's a normal theming pattern, not an error. With the atom-one-light / atom-one-dark themes, hljs-operator is unstyled by design (operators take the base color), so highlighting any code with operators emits this print for every operator token (=, :, {, }, ,, >, …).
In a small benchmark highlighting Swift snippets of 15–400 lines, this print fired 5,585 times in one test pass — all for hljs-operator. The aggregate print() cost (~167 ms) accounted for essentially the entire ~45% Debug-time slowdown of HighlighterSwift vs. raspu/Highlightr (which has no equivalent print). Release is unaffected (#if DEBUG-gated), so this is a Debug-ergonomics issue: console spam + materially slower Debug highlighting.
Repro
let h = Highlighter()!
h.setTheme("atom-one-light")
_ = h.highlight("let x = 1 > 0 ? a : b", as: "swift")
// → "WARNING MISSING STYLE in atom-one-light: hljs-operator" × N
Suggested fix
Remove the print, or gate it behind an opt-in (e.g. a Theme.logsMissingStyles: Bool = false). Missing a style class in the theme dict is the normal "use default" path, not a warning-worthy condition.
Happy to send a PR if helpful.
Theme.applyStyleToStringDEBUG print fires per token for legitimately-unstyled classesLocation:
Sources/Highlighter/Theme.swift:209Problem
This fires once per token whose class isn't in the theme's CSS. But many highlight.js themes intentionally omit classes they want to inherit the default text color — that's a normal theming pattern, not an error. With the
atom-one-light/atom-one-darkthemes,hljs-operatoris unstyled by design (operators take the base color), so highlighting any code with operators emits this print for every operator token (=,:,{,},,,>, …).In a small benchmark highlighting Swift snippets of 15–400 lines, this print fired 5,585 times in one test pass — all for
hljs-operator. The aggregateprint()cost (~167 ms) accounted for essentially the entire ~45% Debug-time slowdown of HighlighterSwift vs. raspu/Highlightr (which has no equivalent print). Release is unaffected (#if DEBUG-gated), so this is a Debug-ergonomics issue: console spam + materially slower Debug highlighting.Repro
Suggested fix
Remove the print, or gate it behind an opt-in (e.g. a
Theme.logsMissingStyles: Bool = false). Missing a style class in the theme dict is the normal "use default" path, not a warning-worthy condition.Happy to send a PR if helpful.