Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue with long text lines #18441

Open
HermanKirshin opened this issue Mar 14, 2025 · 2 comments
Open

Performance issue with long text lines #18441

HermanKirshin opened this issue Mar 14, 2025 · 2 comments

Comments

@HermanKirshin
Copy link
Contributor

Describe the bug

BiDiAlgorithm.ProcessIsolatedRunSequences has O(n²) complexity, and in case of regular left-to-right european alphanumeric texts its calculations even do not affect anything.

Image

To Reproduce

Add TextBlock
Set text to a very long line (i.e. 30kb)
Perform frequent measure (i.e. window resize) - there will be significant freezes

Expected behavior

No response

Avalonia version

11.2

OS

No response

Additional context

No response

@Gillibald
Copy link
Contributor

Gillibald commented Mar 14, 2025

We are already enumerating all codepoints here: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/Media/TextFormatting/Unicode/BiDiData.cs#L93

So we can detect if there is any processing needed.

In general, TextBlock isn't meant to be used with very long text because there is no virtualization

This isn't a bug but a current limitation

@HermanKirshin
Copy link
Contributor Author

HermanKirshin commented Mar 14, 2025

@Gillibald perhaps, if I understood the code correctly, I can suggest the following easy fix, not as fast as detecting and disabling processing completely, but it at least in most cases reduces complexity from O(n²) to O(n). As far as I understand applying rule W2 makes sense only if there are arabic letters, so changing this condition to (hasEN && hasAL) will reduce freezing, if there is no arabic text in the long line. I tried it, textboxes with 30kb sometimes lag a bit, but at least they do not hang the app completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants