xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] [UWP] [Performance] Editor with autosize property is very slow #13097

Open BurkusCat opened 3 years ago

BurkusCat commented 3 years ago

Description

Performance when using the Editor control on UWP with the autosize property set is incredibly slow. Typing individual letters or pasting text becomes noticeably unperformant.

Steps to Reproduce

  1. Create an editor and set autosize on it
  2. Fill the editor with lots of text
  3. Try typing or pasting content in it. In my opinion, it becomes unusable with a small amount of text.

Expected Behavior

Editor performs well for a larger amount of text. I don't think anyone expects an infinite amount of text, but the editor currently gets very bad very quickly.

Actual Behavior

Entering text into an editor slows down dramatically the more text that is entered. I've also experienced general issues with the autosizing where it can interfere with other layouts on the page and cause them to display wrong (I feel like the more complex your layout, the worse the performance can be). A simple layout with a text editor has performance issues too.

Basic Information

Screenshots

I have created a video to demo the issue. The first editor uses auto size. The second editor uses a fixed height and no auto size. Both editors start with 5 paragraphs of lorem ipsum. The test I do is hold down a key on my keyboard for a few seconds and then I hold down Ctrl + V to repeatedly paste a line of text. An editor without auto size can hold magnitudes more text and remain responsive. The autosize editor feels like it loses performance exponentially as more text is added. https://www.youtube.com/watch?v=K7aaRRLb7FU

Reproduction Link

<Editor AutoSize="TextChanges" />

AutosizeEditor.zip

Workaround

Unfortunately, using a fixed height editor is the only solution I've found. This solution isn't great as it means wasted space or the text will overflow beyond the editor with no indication that there is more text to see.

BrayanKhosravian commented 2 years ago

Made a quick analysis. I verified this and it seems like this happens only when around 4200 chars are exceeded. Also created a blank upw project and entered the text causing the issue to a textbox. I didn't implement a line break behavior in that uwp project and the performance was not bad at all. I assume that the issue happens when applying the linebreaks in xf or during the measure and layout cycle.

To fix this, someone should identify the bottleneck and improve or fix it afterwards.