mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09:00
`RenderCodeByLexer` created a new chroma HTML formatter on every call, so the formatter rebuilt the CSS map of the style each time. That runs for every fenced code block in markdown (since https://github.com/go-gitea/gitea/pull/39751) and for every line when the diff view highlights line by line (files over 256 KiB, or after the full-file highlight time limit). The formatter caches that map behind a mutex and is otherwise read-only, so one shared instance is enough. Output is unchanged. Local Go benchmarks, i7-9700 on Windows 11, base and patched run alternately 6 times, medians: | | before | after | |---|---|---| | 1000 lines of `services/gitdiff/gitdiff.go`, one call per line | 115.3 ms, 802k allocs | 40.8 ms, 180k allocs | | 3-line shell code block | 142 µs, 889 allocs | 66 µs, 267 allocs | | Markdown render of README + CONTRIBUTING + 3 docs (45 KB, 31 code blocks) | 16.0 ms, 63.8k allocs | 14.4 ms, 45.8k allocs | This is separate from https://github.com/go-gitea/gitea/pull/40394, which caches highlighted lines but still creates the formatter on each call. Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: silverwind <me@silverwind.io>