| PlainTextStreamParser wraps each source it parses in a BufferedReader, which allocates a 16 KB buffer, even when the source is already in memory, like a StringReader. Allocating this buffer costs more than parsing a short text. This matters for code that parses many short texts, like the code macro, which parses the text of each token of the highlighted code: highlighting a short snippet allocates several megabytes, which slows down the rendering of pages with many code macros, especially when many of them are rendered at the same time. The buffer is only useful for a source that is costly to read character by character, so the parser shouldn't add one to a source that is already in memory or already buffered. |