mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-09 17:37:20 -06:00
Every line of file, blame, diff and code preview views goes through `EscapeControlHTML`, which streamed it through a 32 KiB read buffer and copied every tag and text part. Views render the `EscapeStatus` before the content, so every caller holds the complete HTML and streaming can't help. It is now escaped in one pass over the string and returned unchanged when nothing needs escaping. - Skip text of printable ASCII, tabs and newlines, such lines return immediately - Render markup and wiki pages into a buffer instead of a pipe and goroutine, and remove `EscapeControlReader` - Analyze long text parts in windows overlapping by the detection context, which bounds memory without changing results - Escape invalid bytes before a tag, they were moved into the tag part unescaped and could hide a `<math>` tag | | before | after | |---|---|---| | ASCII line | 5.1 µs, 59 allocs | 0.08 µs, 1 alloc | | line with one `é` | 3.9 µs, 30 allocs | 0.29 µs, 3 allocs | | 150 KB document | 2.5 ms, 5.6 MB | 0.27 ms, 0.6 KB | --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>