[macOS][iOS] Proposal to cache [NS|UI]Screen.MainScreen
derived data
#9098
Labels
difficulty/tbd
Categorizes an issue for which the difficulty level needs to be defined.
kind/bug
Something isn't working
triage/untriaged
Indicates an issue requires triaging or verification
Current behavior
DisplayInformation
is doing too many native (ObjC) calls on values that rarely changes. Here's a sample of the existing code:That's four native (ObjC) calls to return the
Height
.The methods could be optimized, individually, to cache
[NSScreen mainScreen]
saving one native (ObjC) call for each invocation, example:That's only three ObjC calls (and avoids the extra step of multiplication).
Still the following, unavoidable, code pattern remain very inefficient:
since it requires to recompute the same data twice, requiring issuing again the same native calls (twice three ObjC calls).
If this code ends up being called inside a loop (issue) then performance can suffer a lot. The
get_Scale
inside "issue" looks like such an occurrence.Expected behavior
Querying
DisplayInformation
properties should be fast and not appear as bottleneck inside benchmarks.IMHO we can assume that
[1] #9027 (about scale) was found reading the code, not reported as an issue (as far as I know).
How to reproduce it (as minimally and precisely as possible)
Create a loop over some properties of
DisplayInformation
and print the time it takes to go over it.Workaround
Applications can cache the values.
Works on UWP/WinUI
No response
Environment
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
NuGet package version(s)
No response
Affected platforms
iOS, macOS
IDE
No response
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
This affect fixing #9027 since it means replacing the use of very fast
readonly
fields with very slow calls toDisplayInformation
properties.Once the replacement is done the
MainScreen
becomes a large bottleneck inside the Dope benchmark (16 seconds out of the 120 seconds run).Proposal
[NS|UI]Screen
-based values in a single methodThe text was updated successfully, but these errors were encountered: