You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 1, 2024. It is now read-only.
[android/ios] improve perf when not using Application.Properties (#8887)
* [android/ios] improve perf when not using Application.Properties
When profiling startup, I was seeing things like:
Method call summary
Total(ms) Self(ms) Calls Method name
52 0 3 System.IO.IsolatedStorage.IsolatedStorageFile:GetUserStoreForApplication ()
52 0 3 (wrapper remoting-invoke-with-check) System.IO.IsolatedStorage.IsolatedStorageFile:PostInit ()
51 0 3 System.IO.IsolatedStorage.IsolatedStorageFile:PostInit ()
51 0 2 (wrapper remoting-invoke-with-check) System.IO.IsolatedStorage.IsolatedStorageFile:FileExists (string)
51 0 2 System.IO.IsolatedStorage.IsolatedStorageFile:FileExists (string)
49 0 4 System.IO.IsolatedStorage.IsolatedStorageFile:IsPathInStorage (string)
This app has no `Properties` at all, but it seems to still be doing
the file I/O for it.
I found that a file was being written that contain a serialized empty
dictionary:
> adb shell run-as com.xamarin.forms.helloforms cat /data/user/0/com.xamarin.forms.helloforms/files/.config/.isolated-storage/PropertyStore.forms
@▲ArrayOfKeyValueOfstringanyTyp9http://schemas.microsoft.com/2003/10/Serialization/Arrays ☺i)http://www.w3.org/2001/XMLSchema-instance☺
Any subsequent startup would parse this file.
Two changes will help here:
1) For writes, use a single instance of:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
It appears this call is expensive.
2) On writes, we don't need to write a file at all if the `Properties`
dictionary is empty and no file is on disk. This way apps that
don't use `Properties` at all won't load a file with an empty
dictionary.
~~ Results ~~
Using a Release build of the Blank Forms app template on a Pixel 3 XL:
Before:
12-13 14:01:42.826 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +606ms
12-13 14:01:46.541 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +588ms
12-13 14:01:50.325 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +597ms
12-13 14:01:54.088 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +600ms
12-13 14:01:57.855 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +579ms
12-13 14:02:01.619 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +594ms
12-13 14:02:05.371 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +605ms
12-13 14:02:09.106 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +597ms
12-13 14:02:12.869 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +600ms
12-13 14:02:16.635 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +601ms
Average(ms): 596.7
Std Err(ms): 2.56493448042808
Std Dev(ms): 8.11103500725332
After:
12-13 13:59:46.260 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +600ms
12-13 13:59:49.993 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +579ms
12-13 13:59:53.739 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +587ms
12-13 13:59:57.506 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +592ms
12-13 14:00:01.255 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +586ms
12-13 14:00:05.007 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +580ms
12-13 14:00:08.841 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +581ms
12-13 14:00:12.587 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +591ms
12-13 14:00:16.320 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +585ms
12-13 14:00:20.052 1490 1517 I ActivityTaskManager: Displayed com.xamarin.forms.helloforms/crc6450e568c951913723.MainActivity: +577ms
Average(ms): 585.8
Std Err(ms): 2.23507394856536
Std Dev(ms): 7.06792441637257
I think this change saves ~10ms on startup for apps that don't use
`Application.Properties` at all.
I made this change for Android & iOS, as they had similar
implementations.
* Moved the properties check earlier
This way it won't even open the Stream on writes when there are no
properties.
* [tizen] include the same optimization
As suggested by @rookiejava:
#8887 (review)
* [tizen] make implementation match Android exactly
Context: #8887 (comment)
As suggested by @rookiejava, we can make the implementation match
other platforms exactly.
I took the changes as-is, except matched the formatting in Android's
`Deserializer.cs` so the two files are identical except for the
namespace. I also had to use `Internals.Log`.
0 commit comments