-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Regression] [Android] [Maps] Map locks up after rendering 50 Polylines #20502
Comments
Hi @mfeingol. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Added a repro link: https://github.com/mfeingol/repros/tree/master/LotsOfPolylinesRepro And now I'm not sure this actually did work in 8.0.3. But it is 100% a regression from Xamarin.Forms, where this same scenario works well. |
@mfeingol Can you create a repo of this working in Xamarin.Forms? That would help track down what changed for why it worked in Forms, but not MAUI. |
Hi @mfeingol. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@drasticactions: sorry to bug, but were you able to make any progress on this issue? It's a pretty critical showstopper for my app, and we're not far away from XF deprecation... Thanks. |
I apologize, I'm not on the MAUI Team. It says "Member" as I'm within So no, I haven't made progress. |
@samhouts: sorry to ping you directly, but is there someone on the team I can work with on this? As mentioned above, this is a pretty critical showstopper for my app and we're not far away from XF deprecation... Thanks. |
@jonathanpeppers Is this something you could take a look at and see if there's something obvious we can resolve here? Thanks!! |
@mfeingol it doesn't say above, were you using If not, you were comparing the JIT vs Interpreter. The interpreter is on by default for More information about this is mentioned here: https://aka.ms/profile-maui#feature-xyz-was-faster-in-xamarinforms |
@jonathanpeppers: I first observed the problem in release builds on a physical device. I then isolated the repro in the debugger with debug builds. Either way, the scenario works in Xamarin Forms and locks up hard in MAUI. |
@mfeingol do you think it's related to the |
@jonathanpeppers: I replaced |
@jonathanpeppers: also of note, if I move the |
Okay, so I think the issue is on https://github.com/dotnet/maui/blob/main/src/Core/maps/src/Handlers/MapElement/MapElementHandler.Android.cs#L103 This sends the GC into a tailspin: foreach (var position in geoPathMapElement)
{
polylineOptions.Points.Add(new LatLng(position.Latitude, position.Longitude));
} While this seems to work more or less okay: polylineOptions.Add(geoPathMapElement.Select(p =>new LatLng(p.Latitude, p.Longitude)).ToArray()); @jonathanpeppers: maybe worth investigating why the GC can't handle the first pattern? |
@mfeingol I don't think there is a problem with the GC here. If I understand correctly, there is a problem if you do:
But it works if you do:
It looks to me this would be called N times in the first case, adding the same points over and over?
Does that match with the behavior you're seeing? I'm not a huge fan of the handler architecture as it creates some problems like this one, and also: |
@jonathanpeppers: the first case isn't adding the same points over and over. It's adding N points one by one vs. adding all of them a batch. Which really shouldn't be a big deal, I guess. On that note, on closer examination I am no longer confident that the difference I mentioned above is the core problem. I've added a workaround to this issue in my own code that uses the Android-native So... I think I may be landing on your conclusion, which is that perhaps MapElementHandler.MapGeopath is being called repeatedly in the pure Maui case, thus generating lots and lots of garbage. Ideally someone with a debug build of Maui's MapElementHandler would look to see whether this is the case. |
Yes, it appears to me if you did:
To the point CPU and/or memory are quickly exhausted if the number N is decently large. |
Anecdotally, I set a bp in the decompiled source for |
You'd need to put a breakpoint in the handler / |
Yeah, I put it after the comment in this if (handler.PlatformView is PolylineOptions polylineOptions)
{
// Will throw an exception when added to the map if Points is empty
if (geoPathMapElement.Count == 0) // <<<--- BP HERE
{
polylineOptions.Points.Add(new LatLng(0, 0));
}
else
{
foreach (var position in geoPathMapElement)
{
polylineOptions.Points.Add(new LatLng(position.Latitude, position.Longitude));
}
}
} |
Hello, I also really need this solution. I had an app made in "Kodular" where I inserted line by line in a "foreach" A[i] to B[i], it was capable of compiling more than a thousand points easily on the Google Maps, Note: instantiating more than a thousand points is very fast, less than 1 second, The function that takes about 1 minute for 1000 points is the Please create a new function similar to the one below: |
A workaround could be, only render the polylines in the visible region, or reduce the number of lines (500 in the sample) from every Polyline. Could use the Douglas-Peucker algorithm for example. |
We shouldn't have to apply a complex workaround like this to address a regression in functionality in .NET MAUI vs Xamarin Forms. |
Hello, jsuarezruiz. Thank you for the tip about the "Douglas-Peucker" algorithm; I wasn't aware of it. I created my own algorithm in a simple way by searching for the nearest point, similar to DBSCAN. Some points in my dataset have a final coordinate equal to the starting coordinate of the next point; however, when there are elements between the points, they usually have a distance of up to 15 meters. I work at an electricity distribution company and I use this to plot our distribution network cables on Google Maps. I limited it to 270 polygon groups, but sometimes it fails if the polygon is too large (with many points). I am not able to plot all our "feeder networks" because some are too large. There are several points where MAUI needs improvement, such as changing the colors of the pins and custom icons. Perhaps the solution is to migrate to another framework until MAUI MAPS is more mature. |
You can change the color of the pins and set custom icons of the map. More information here : Customize Map Pins in .NET MAUI by vladislavantonyuk There other maps available, like Mapsui , although I do not recommend it for beginners because documentation is lacking. Maui.GoogleMaps is a pretty nice nuget package that offers interesting functionality as alternative to Maui.Maps. One advantage of MAUI, similar to Xamarin, is the possibility to bind native Java Libraries. This means you can integrate any native Android Java library into your app. There are countless of native Android libraries, for sure you can find something that does what you need. But most times integrating those libraries is a diffcult task. |
Description
My app has a scenario in which it renders a number of GPX tracks. When this number is relatively large (50), the process hangs and appears to be stuck in an infinite loop. Nothing visible in the managed debugger, but endless trace output like this:
Steps to Reproduce
Run the repro app. Inside the app, click on the
Lots of Polylines
option at the bottom of the menu.If the page renders a map with some lines, then the test succeeded and there is no bug.
If the app hangs with unhappy GC messages, then the bug has been reproduced.
Change the
count
andsteps
values in theLotsOfPolylinesPage
class to simulate a different number of tracks and number of locations in each track. The app falls over at around 46000 total locations.Link to public reproduction project repository
https://github.com/mfeingol/repros/tree/master/LotsOfPolylinesRepro
Version with bug
8.0.6
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
8.0.3
Affected platforms
Android
Affected platform versions
13
Did you find any workaround?
No workaround.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: