-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Very low Text Rendering Performance due native C++ interop #4768
Comments
There is the fastest font renderer in the Rust language. Would make sense to create bindings for it and let fontdue do the work. |
Instead of switching from C++ to Rust and still having calls to native code (with allocations and overhead), wouldn't it be better to check if the code can be replaced with C# instead? Now that we have Span etc. I don't know if we need any native code here at all. In the .NET runtime repo they're trying to get rid of all native calls because of performance issues. |
@Symbai You're right about that. Are there any benchmarks on how much performance the native overhead takes away? |
WPF does not support AOT. There were benchmarks on .NET repo on each commit where they got rid of native code but I don't have any links. The best would be someone (else, because I have no idea what the code does) re-writes the code in C# and compare both. But then it needs to be reviewed by the new WPF repo owners and they are not very good on that. |
@deeprobin can you provide a repro sample? |
@miloush I think this should be easily achieveable when you create a large grid view with lots of columns and rows and then scroll thorugh it. When virtualization is enabled, textblocks get lots of updates. |
@IAmTheCShark This is exactly what I meant in DataGrid and this makes scrolling very unperformant. And it shouldn't be like that. |
@deeprobin I wrote a small hack that uses reflection to turn on some optimizations. Obviously, this is nothing for productoin enivronment and only for testing purposes. This might have weird consequences so use with cuaiton. The hack will make Typeface.CheckFastPathNominalGlyphs (https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/Media/Typeface.cs,550) return true alot more often Paste the following code into your MainWindow constructor before InitializeComponent or before you create all the TextBlocks.
` |
Hey @IAmTheCShark, I just tried your Reflection hack. It makes a minimal difference for me, but it's not an improvement that drastically improves performance. Has the reimplementation in C# already been started, if so, does a branch already exist for it? |
I have adapted your solution a bit and added a custom rendering using SkiaSharp and notice that the scrolling is significantly smoother. Maybe it would be the best solution in the long run to switch from DWrite to SkiaSharp (first for the text rendering). |
Problem description:
UIElement.Measure this very slow
Actual behavior:

Expected behavior:
Fast measuring for WPF rendering.
If there is nothing more that can be optimized in the measure method, it might make sense to cache the measures according to certain parameters, since this is very slow with large visual trees.
Compared to Windows Forms, Windows Forms is superior in terms of performance here.
Would it not make sense to write the measure method in native C++ somehow to optimize the performance accordingly or is the overhead here too large?
Minimal repro:
The text was updated successfully, but these errors were encountered: