-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
FontImageSource renders slow on Android in ImageButton and Image #22757
Comments
Hi I'm an AI powered bot that finds similar issues based off the issue title. Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you! Open similar issues:
Closed similar issues:
|
Verified this issue with Visual Studio 17.11.0 Preview 1(9.0.0-preview.4.10690/9.0.0-preview.2.10293/8.0.40/8.0.21/8.0.3). Can repro on android platform with sample project. |
I cannot repro this on the latest 8.0.40 nor the latest nightly nor main. If this is just net9, then maybe we need to test again after the main branch is merged. |
I managed to repro this on net9 using Preview 4 bits. I do get a bit different results, the initial load is like a few ms before the image appears, but then it is fast from then on. |
I see I am getting this now on my devbox... So on my mac, all net8 versions seem to work. On the Windows devbox, all versions seem to be broken. The devbox seems to have acceleration issues - or that is what it said when I booted but I am not sure. However, this all depends now before I start destroying my local machines. What type of machines are you using @davidortinau and @kevinxufei ? Physical machines? Remote desktops? Dev boxes? VMs? |
OK, looking at Windows machine, I see a very very small delay. My M1 mac has no delay, my Surface Laptop Studio is mostly good but there is like a 100-200ms delay, devbox is got a big flash. I tested on my Samsung A53 and it seemed OK... Maybe the emulators are making a small issue with the fact that the images are bing generated on the fly become more obvious. Not sure if ayone sees this on a real device or on a real machine - or is this in devoxes/VMs that might not have accelerated hardware? |
Testing some more on the slow devbox I found something interesting. I wrote this code: // var imageSource = new FileImageSource
// {
// File = "dotnet_bot.png"
// };
var imageSource = new FontImageSource
{
FontFamily = "FontAwesome",
Color = Colors.Black,
Glyph = IconFont.FootballBall
};
var sw = new Stopwatch();
sw.Start();
var mauiContext = Handler.MauiContext;
var provider = mauiContext.Services.GetService<IImageSourceServiceProvider>();
var service = provider.GetRequiredImageSourceService(imageSource);
#if ANDROID
var result = await service.GetDrawableAsync(imageSource, mauiContext.Context);
#endif
sw.Stop();
await DisplayAlert("TIME", sw.ElapsedMilliseconds.ToString(), "OK"); When using a
BUT... I do notice that 8.0.40 is about 100ms slower the inital run (about 550-600ms) and 50ms on subsequent runs (about 30-100ms). This also looks to just affect the |
I generated a speedscope of a Release build of 8.0.40 and there is very much a large set of interop happening. I wonder if something in the AOT profile change of we need to add it into the profile. |
Tracking some timings (every day I run them I get totally new numbers): 8.0.40 (8.0.40+azdo.9568816)
8.0.21 (8.0.21+0-sha.44a1673f7d-azdo.9442930.44a1673f7d2da631396ec9820e1d5cf3c29c9b1a)
8.0.20 (8.0.20+0-sha.195c36c4a6-azdo.9385637.195c36c4a6e742f2c6393a002df2902ce3a508a4)
8.0.10 (8.0.10+0-sha.50a0144fa5-azdo.9223550.50a0144fa5d17bca177da784803efd971a54800f)
8.0.6 (8.0.6+1-sha.87f59a86d4-azdo.8922564.87f59a86d453c8bcf4f5db0fb21259083b0d2d76)
8.0.3 (8.0.3+2-sha.1ebb238ff3-azdo.8651303.1ebb238ff313b626fe40e33fb52bdf13697ede5c)
|
A better speedscope with a single load and nothing else: |
I rebooted my emulator and now all the numbers are the same... So basically, not the proof anymore. Looks like the longer an emu runs the slower it becomes. But if I look at the numbers, the do have a small different - 180ms to 300ms - which is about 100ms difference. This is most likely the AOT profile, but I will still try find some better answers. However, testing 8.0.3 results in the same delay. I don't think this is a regression nor a new issue as a result of a slower load. Seems to just be slow devices. Somehow. |
I just verified that the issue still is happening in 8.0.60. |
I think we found that there was no caching for the font images, so this PR will hopefully fix it a fair bit: #24021 |
This is a benchmark from #24021 [Benchmark]
public async Task ImageHelperFromFont()
{
var callback = new Callback();
handler!.Post(() =>
{
Microsoft.Maui.PlatformInterop.LoadImageFromFont(
context,
Android.Graphics.Color.Aquamarine,
"A",
Typeface.Default,
24,
callback);
});
await callback.SuccessTask;
} Before
After
|
@gautambjain I think this might be a different issue. |
Thanks @albyrock87 . I already had a fixed size of 28 on Image. The RowDefinition on the grid is set to Auto. So the row shows smaller and then larger as shown in video. But I kind of fixed the row height by fixing the surrounding StackLayout MinimumHeightRequest to 28. Now the ListView rows show a bigger initial size but still the fonts appear little later. And there are more font icons I am using in the same list row (folder icon, alarm icon, contact icon) and I want them to show bigger when the user changes the default display/text size (scaled text and display). But don't you think the actual issue of delayed FontImageSource loading still is shown in my video? What I did above is only a work around. But it will not work for all font icons and all scaled displays. It will still show a flicker like in the video. |
@gautambjain use
Then start the app and reach you page and look at logs. A sample load not from cache, see
A sample load from cache, see
Now I would expect lots of them being loaded from cache. Talking about MAUI internals, to load images we're using https://github.com/bumptech/glide library. In your case all images are appearing in the same moment for the first time, so maybe that means that none of them will find the image in cache. I cannot understand what you're doing in the app from the video, but it seems you're suddenly displaying a collection view with some items.
Now, on step 1, may you try to display all the icons somewhere in the page (with the same This should bring them into the memory cache and load should be immediate. Let me know how it goes, and anyway, it'd be useful to have a simple |
Description
In debug I can see the images paint, initially very slowly and then the second time I navigate they still draw much slower for
ImageButton
andImage
than forLabel
.FontThings.zip
Android:
slow.iconfont.rendering.mov
iOS for comparison is fine.
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-05-31.at.09.03.06.mp4
9.0.0-preview.4.10690
I tested a release build, and while the first draw is faster, going between pages still has the icons bouncing around as they measure and layout.
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
9.0.0-preview.3.10457
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.40 SR5
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: