Skip to content

Commit 1622eee

Browse files
Mattias PeterssonDianne Hackborn
authored andcommitted
Improve performance of WindowState.toString()
This fix improves the performance by caching the string that should be returned, and reuse it next time if possible. This will make it faster to switch between activities, approximately half the time to create the new view when changing from landscape to portrait. Also, the time for starting a new application is be reduced as WindowState.toString is being called thousands of times in this case. Change-Id: I2b8b9bc1e251d1af43b6c85f049c01452f2573a2
1 parent 3ce8648 commit 1622eee

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

services/java/com/android/server/WindowManagerService.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6003,6 +6003,11 @@ private final class WindowState implements WindowManagerPolicy.WindowState {
60036003
// Input channel
60046004
InputChannel mInputChannel;
60056005

6006+
// Used to improve performance of toString()
6007+
String mStringNameCache;
6008+
CharSequence mLastTitle;
6009+
boolean mWasPaused;
6010+
60066011
WindowState(Session s, IWindow c, WindowToken token,
60076012
WindowState attachedWindow, WindowManager.LayoutParams a,
60086013
int viewVisibility) {
@@ -7260,9 +7265,14 @@ String makeInputChannelName() {
72607265

72617266
@Override
72627267
public String toString() {
7263-
return "Window{"
7264-
+ Integer.toHexString(System.identityHashCode(this))
7265-
+ " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7268+
if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
7269+
|| mWasPaused != mToken.paused) {
7270+
mLastTitle = mAttrs.getTitle();
7271+
mWasPaused = mToken.paused;
7272+
mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
7273+
+ " " + mLastTitle + " paused=" + mWasPaused + "}";
7274+
}
7275+
return mStringNameCache;
72667276
}
72677277
}
72687278

0 commit comments

Comments
 (0)