Skip to content

Commit

Permalink
Revert "Pre-emptively take a snapshot when finishing an activity befo…
Browse files Browse the repository at this point in the history
…re changing visibility"

This reverts commit 6dad90e.

When opening and closing activities in Settings, a significant amount of
CPU time is spent rendering and compressing JPEG screenshots, as
reported by simpleperf:

0.46%     /system/lib64/libjpeg.so                                                                                                                  encode_mcu_gather
0.37%     /system/lib64/libhwui.so                                                                                                                  neon::S32_alpha_D32_filter_DX(SkBitmapProcState const&, unsigned int const*, int, unsigned int*)
0.29%     /system/lib64/libjpeg.so                                                                                                                  jsimd_extrgbx_ycc_convert_neon
0.27%     /system/lib64/libjpeg.so                                                                                                                  jsimd_fdct_islow_neon
0.23%     /system/lib64/libjpeg.so                                                                                                                  jsimd_huff_encode_one_block_neon
0.14%     /system/lib64/libjpeg.so                                                                                                                  jsimd_quantize_neon

Call graph tracing reveals that TaskSnapshotPersister is responsible for
taking the screenshots:

0.16%     0.16%  /system/lib64/libjpeg.so                                                                                                encode_mcu_gather
       |
       -- encode_mcu_gather
          |
           --50.00%-- compress_output
                      process_data_simple_main
                      jpeg_write_scanlines
                      SkJpegEncoder::onEncodeRows(int)
                      SkJpegEncoder::Encode(SkWStream*, SkPixmap const&, SkJpegEncoder::Options const&)
                      SkEncodeImage(SkWStream*, SkPixmap const&, SkEncodedImageFormat, int)
                      android::Bitmap::compress(SkBitmap const&, android::Bitmap::JavaCompressFormat, int, SkWStream*)
                      android::Bitmap::compress(android::Bitmap::JavaCompressFormat, int, SkWStream*)
                      Bitmap_compress(_JNIEnv*, _jobject*, long, int, int, _jobject*, _jbyteArray*)
                      art_jni_trampoline
                      android.graphics.Bitmap.compress
                      com.android.server.wm.TaskSnapshotPersister$StoreWriteQueueItem.writeBuffer
                      com.android.server.wm.TaskSnapshotPersister$StoreWriteQueueItem.write
                      com.android.server.wm.TaskSnapshotPersister$1.run
                      art_quick_invoke_stub
                      art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)
                      art::JValue art::InvokeVirtualOrInterfaceWithJValues<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, jvalue const*)
                      art::Thread::CreateCallback(void*)
                      __pthread_start(void*)
                      __start_thread

Manual code tracing leads to ActivityRecord as the culprit, as it takes
a screenshot every time an Activity is finished. This doesn't appear to
be critical, so revert the commit that added it in order to reduce
excess CPU usage.

Test: simpleperf record -a; verify that libjpeg-turbo no longer appears
      in top sample hits
Change-Id: Ib161679f1f3b83787f90b8ef7dcf46d246bb7c57
  • Loading branch information
kdrag0n committed Jun 7, 2022
1 parent 10b54a5 commit 4d99b14
Showing 1 changed file with 0 additions and 15 deletions.
15 changes: 0 additions & 15 deletions services/core/java/com/android/server/wm/ActivityRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@
import com.android.server.wm.WindowManagerService.H;
import com.android.server.wm.utils.InsetUtils;

import com.google.android.collect.Sets;

import org.xmlpull.v1.XmlPullParserException;

import java.io.File;
Expand Down Expand Up @@ -3145,19 +3143,6 @@ private void finishActivityResults(int resultCode, Intent resultData,
}
mDisplayContent.prepareAppTransition(TRANSIT_CLOSE);

// When finishing the activity preemptively take the snapshot before the app window
// is marked as hidden and any configuration changes take place
// Note that RecentsAnimation will handle task snapshot while switching apps with
// the best capture timing (e.g. IME window capture),
// No need additional task capture while task is controlled by RecentsAnimation.
if (mAtmService.mWindowManager.mTaskSnapshotController != null
&& !task.isAnimatingByRecents()) {
final ArraySet<Task> tasks = Sets.newArraySet(task);
mAtmService.mWindowManager.mTaskSnapshotController.snapshotTasks(tasks);
mAtmService.mWindowManager.mTaskSnapshotController
.addSkipClosingAppSnapshotTasks(tasks);
}

// Tell window manager to prepare for this one to be removed.
setVisibility(false);

Expand Down

0 comments on commit 4d99b14

Please sign in to comment.