Skip to content

Commit 33b4324

Browse files
Mattias PeterssonJohan Redestig
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 e78a000 commit 33b4324

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
@@ -6005,6 +6005,11 @@ private final class WindowState implements WindowManagerPolicy.WindowState {
60056005
// Input channel
60066006
InputChannel mInputChannel;
60076007

6008+
// Used to improve performance of toString()
6009+
String mStringNameCache;
6010+
CharSequence mLastTitle;
6011+
boolean mWasPaused;
6012+
60086013
WindowState(Session s, IWindow c, WindowToken token,
60096014
WindowState attachedWindow, WindowManager.LayoutParams a,
60106015
int viewVisibility) {
@@ -7262,9 +7267,14 @@ String makeInputChannelName() {
72627267

72637268
@Override
72647269
public String toString() {
7265-
return "Window{"
7266-
+ Integer.toHexString(System.identityHashCode(this))
7267-
+ " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7270+
if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
7271+
|| mWasPaused != mToken.paused) {
7272+
mLastTitle = mAttrs.getTitle();
7273+
mWasPaused = mToken.paused;
7274+
mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
7275+
+ " " + mLastTitle + " paused=" + mWasPaused + "}";
7276+
}
7277+
return mStringNameCache;
72687278
}
72697279
}
72707280

0 commit comments

Comments
 (0)