Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AndroidVitals徹底活用

Avatar for kr9ly kr9ly
February 08, 2019

 AndroidVitals徹底活用

Avatar for kr9ly

kr9ly

February 08, 2019
Tweet

More Decks by kr9ly

Other Decks in Programming

Transcript

  1. 起動時間を取る場合 Application.onCreateの先頭でスタート public class KurashiruApplication extends Application { @Override public

    void onCreate() { super.onCreate(); Debug.startMethodTracing("sample", 200 * 1024 * 1024); ... } }
  2. 最初のフレームの表⽰まで取るのがおすすめ public class MainActivity { @Override protected void onCreate(Bundle savedInstanceState)

    { ... setContentView(R.layout.activity_main); new Handler().postDelayed(new Runnable() { @Override public void run() { Debug.stopMethodTracing(); } }, 16); ... } }
  3. Daggerの初期化処理が遅い(Cognitoの初期化 処理が遅い) public class EventLogSender { private final KinesisFirehoseRecorder recorder;

    @Inject public EventLogSender(KinesisFirehoseRecorder recorder) { this.recorder = recorder; } ... } Injectする際の初期化処理に時間がかかっている
  4. Lazy<T>を使う public class EventLogSender { private final Lazy<KinesisFirehoseRecorder> recorderLazy; @Inject

    public EventLogSender(Lazy<KinesisFirehoseRecorder> recorderLazy) { this.recorderLazy = recorderLazy; } public void send() { doBackground(() -> { recorderLazy.get(); }) } }
  5. バックグラウンドスレッド上で初期化 public class KurashiruApplication extends Application { @Override public void

    onCreate() { ... doBackground(() -> { ZoneId.systemDefault(); }); } } Application.onCreateの先頭でやればある程度の短縮が⾒込める
  6. トリガーの仕込みがキモ public void onScrollChange(RecyclerView recyclerView, int dx, int dy) {

    if (dy > 200) { Debug.startMethodTracing("sample", 200 * 1024 * 1024); new Handler().postDelayed(() -> { Debug.stopMethodTracing(); }, 16); } } 閾値を超えたスワイプを検知したら1フレーム分測定