beto-rodriguez / LiveCharts2

Simple, flexible, interactive & powerful charts, maps and gauges for .Net, LiveCharts2 can now practically run everywhere Maui, Uno Platform, Blazor-wasm, WPF, WinForms, Xamarin, Avalonia, WinUI, UWP.
https://livecharts.dev
MIT License
4.39k stars 574 forks source link

perf: MAUI MotionCanvas - only fetch density from MainDisplayInfo when changed #1626

Closed Kay-STL closed 1 month ago

Kay-STL commented 1 month ago

Currently, the MAUI MotionCanvas queries MainDisplayInfo on every paint in order to fetch the screen density. Querying MainDisplayInfo on Android (11, at least) drops into Java interop to call system services - this can take a decent chunk of time, occasionally upwards of 15% of the total paint time in the application I'm profiling.

This PR tweaks the MotionCanvas to query MainDisplayInfo once in the constructor, then register a MainDisplayInfoChanged handler to update it if truly necessary.

Tested on Android, iOS, and Windows with no issues.

beto-rodriguez commented 1 month ago

occasionally upwards of 15% of the total paint time in the application I'm profiling

Pff that is an amazing improvement, thanks for the PR