Giter Site home page Giter Site logo

Comments (9)

zaksmolen avatar zaksmolen commented on August 16, 2024

I am still noticing this with current versions of AvalonEdit. I even turned off syntax highlighting and collapsing and even so, when I have a decent size block selection and try to type sometimes it takes a second per character.

Anyone have any ideas about fixes or optimizations? We unfortunately have a lot of people doing block selecting in our application...

from avalonedit.

zaksmolen avatar zaksmolen commented on August 16, 2024

I have noticed that some of the things mentioned in #9 do help. Turning off space showing does make it a little faster, but we need spaces shown, and also it really seems to happen more with block select.

from avalonedit.

goswinr avatar goswinr commented on August 16, 2024

@siegfriedpammer could this be fixed by using Document.BeginUpdate() and Document.EndUpdate()
Or are you doing this already?
Could you point me at the relevant code, so that I can maybe try a PR ...

from avalonedit.

zaksmolen avatar zaksmolen commented on August 16, 2024

I would be happy to take a look at this as well if someone could point me to the relevant area in the code. We finally were able to update our VS version so I can actually give fixing this a try!
Our users are literally copy/pasting in/out of WordPad or NP++ in order to do block selection and typing because that's faster than trying to do it in the editor.

from avalonedit.

zaksmolen avatar zaksmolen commented on August 16, 2024

@goswinr I'm looking at the code and they do seem to have that area of code wrapped with using (textArea.Document.RunUpdate()) (so it does begin/end update), so that's not going to change anything.

I did some benchmark testing on my brand new and decently high-spec computer, timing this section of the code:

foreach (SelectionSegment lineSegment in this.Segments.Reverse()) {
	ReplaceSingleLineText(textArea, lineSegment, newText, out insertionLength);
	totalInsertionLength += insertionLength;
	firstInsertionLength = insertionLength;
}

~100 lines took consistently 1.5-4 seconds
~500 lines took consistently almost a full minute

Looking a little deeper, the slowest part of ReplaceSingleLineText() seems to be the Document.Insert() and Document.Replace() calls. To similar examples as before:
~180 lines too about 22ms per call
~540 lines took about 125ms per call

So first off, even without too many lines, that's quite slow for an action that's done for each line. 22ms * 180 lines is about 4 seconds just for the Insert() calls. That means 4+ seconds per character press if you're trying to type in just 180 lines. With 540 lines it took over a full minute, again meaning that if you're trying to type in a block selection, you have to wait over a minute per key press.

I'm curious why the time in that function jumps so high. A 3x increase in lines consistently increased the call time by 5x, and that's nowhere near the max amount of lines our users would want to be able to select.

from avalonedit.

zaksmolen avatar zaksmolen commented on August 16, 2024

Just to add more as I debug, 90+% of the time is in TextArea.OnDocumentChanged() and almost all of that is the selection.UpdateOnDocumentChange(e) line. So it's the UpdateOnDocumentChange() method of RectangularSelection.

I'm not sure why the selection needs to be updated after each line of a change, and not just at the end. I.e. it seems like this update should be deferred by some mechanism if the change is triggered by a rectangular selection action.

Just for testing I commented out the changed event call (TextDocument.cs around line 877), it didn't seem to have any changes to behavior (visually things still seem to update) but the 500 line change takes 1-1.5 seconds per character, an order of magnitude difference. 100 lines was still the slightest bit jumpy, but markedly better at around 0.2-0.25 seconds for per character.

Also, just a note, the debugging output to time things that I have been putting in for testing is actually slowing stuff down. With no debugging output, and only timing the whole change, it takes on average about 0.1 seconds per character press for 500 lines. But for the purpose of debugging, the overhead added should be relatively constant (make 2 DateTimes, subtract them, and log it to the console).

from avalonedit.

zaksmolen avatar zaksmolen commented on August 16, 2024

Ugh, well the side effect of not calling Changed() around line 877 is that it doesn't update the caret for normal typing.

from avalonedit.

goswinr avatar goswinr commented on August 16, 2024

@zaksmolen I could significantly improve the performance of typing in a rectangle selection by using TextArea.PreviewTextInput event , then doing the block edit myself via a Stringbuilder and then call doc.Replace only once. maybe something similar might help you. Changing the font or reducing the syntax highlighting might help too see #252

from avalonedit.

zaksmolen avatar zaksmolen commented on August 16, 2024

I believe I have finally resolved this in pull request 269.

from avalonedit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.