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
Synchronize warming the reflection cache (airbnb#244)
In addition, we should have been checking for KVisibility == PUBLIC not isAccessible. As is, the second part of the reflection warming was filtering out all properties.
Here is a benchmark in which I switched from FlowViewModel in which I added 80 @PersistState properties to another app and back several times with background processes turned off
without declaredMemberProperties warming:
06-14 08:05:05.240 5295 5344 D Gabe : persistState: 21
06-14 08:05:05.308 5295 5295 D Gabe : persistState: 7
06-14 08:05:09.341 5390 5431 D Gabe : persistState: 32
06-14 08:05:12.328 5390 5390 D Gabe : persistState: 7
06-14 08:05:16.948 5484 5517 D Gabe : persistState: 28
06-14 08:05:19.604 5484 5484 D Gabe : persistState: 4
06-14 08:05:24.098 5569 5599 D Gabe : persistState: 37
06-14 08:05:24.568 5569 5569 D Gabe : persistState: 5
06-14 08:05:28.866 5652 5682 D Gabe : persistState: 16
06-14 08:05:29.542 5652 5652 D Gabe : persistState: 5
06-14 08:05:34.043 5736 5769 D Gabe : persistState: 21
with declaredMemberProperties warming:
06-14 08:05:50.617 5865 5916 D Gabe : persistState: 5
06-14 08:05:50.670 5865 5865 D Gabe : persistState: 8
06-14 08:05:54.826 5971 6004 D Gabe : persistState: 9
06-14 08:05:54.981 5971 5971 D Gabe : persistState: 3
06-14 08:05:59.318 6067 6100 D Gabe : persistState: 5
06-14 08:05:59.811 6067 6067 D Gabe : persistState: 5
06-14 08:06:03.791 6149 6185 D Gabe : persistState: 9
06-14 08:06:04.899 6149 6149 D Gabe : persistState: 4
06-14 08:06:10.128 6235 6265 D Gabe : persistState: 5
06-14 08:06:15.794 6318 6351 D Gabe : persistState: 6
Fixesairbnb#231
@@ -66,8 +55,25 @@ abstract class BaseMvRxViewModel<S : MvRxState>(
66
55
}
67
56
}
68
57
69
-
internalval state:S
70
-
get() = stateStore.state
58
+
/**
59
+
* Kotlin reflection has a large overhead the first time you run it
60
+
* but then is pretty fast on subsequent times. Running these methods now will
61
+
* initialize kotlin reflect and warm the cache so that when persistState() gets
62
+
* called synchronously in onSaveInstanceState() on the main thread, it will be much faster.
63
+
* This improved performance 10-100x for a state with 100 @PersistState properties.
64
+
*
65
+
* This is also @Synchronized to prevent a ConcurrentModificationException in kotlin-reflect: https://gist.github.com/gpeal/27a5747b3c351d4bd592a8d2d58f134a
0 commit comments