Closed ivanceras closed 1 year ago
This doesn't surprise me:
TextBuffer
structure is close to ideal for the kind of iteration you're doing. You're iterating over lines, and then over the char
s in each line. And TextBuffer
has already done all of the processing to split the lines and generate the char
s. So you basically have no overhead other than the iterating over arrays, which is extremely fast.char
s on the fly as it iterates. And additionally, in your Ropey-based code but not your TextBuffer
-based code, you're making a full copy of each line via the chars iterator (let line_str = String::from_iter(line.chars());
), which is not exactly efficient.So I'm not sure why you would expect Ropey to be faster here. You've basically purpose-made a data structure for exactly this kind of processing, and are comparing against something that is instead optimized for editing large texts. That isn't to say that Ropey's line iterator couldn't be faster than it is now, but it will certainly never be faster than almost zero overhead, which is what you've built here.
I have a simple test to check the time it took for highlighting a line returned from a
Rope
and from a simpleTextBuffer
. It seems that highlighting lines coming fromRope
is almost 2x slower.The
TextBuffer
at it's core is just aVec<Vec<Ch>>
and Ch is just:I'm expecting
ropey
to be faster than a simpleVec of Vec of chars
structure. The width here is needed because I present the lines visually in rendering the text which depends on the unicode of the character.This is the code for iterating and highlighting the lines for each implementation.
And the test to see which one is much faster.
To quickly replicate this test: