material-components / material-components/material-components-android

[MaterialDatePicker + MaterialTimePicker] (Maybe others as well) slow load time

Open
#1,910 8 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Issue: Performance Widget: DatePicker Widget: TimePicker
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Description:

I want to use those components in my app but I notice some really unusual loading speed for the initial load after the app is cold started. It takes up to three seconds for the pickers to show up after they are requested.

ezgif-1-496c20434c9e

That behaviour happens when I start the application from Android Studio on my phone or in the emulator. When I use the Sample App for the Material Components from the PlayStore it's behaving normally (so no opening delay). I'm actually kinda clueless what the reasoning might be.

Consecutive clicks are faster.

Expected behavior:

The Pickers should show up nearly instantaneously.

Source code:

This screencapture is from a minimal application that consists just of one Activity:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById<Button>(R.id.datePicker).setOnClickListener {
            MaterialDatePicker.Builder.datePicker().build().show(supportFragmentManager, "DATE_PICKER")
        }

        findViewById<Button>(R.id.timePicker).setOnClickListener {
            MaterialTimePicker.Builder().build().show(supportFragmentManager, "DATE_PICKER")
        }
    }
}

The layout just contains the two buttons:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/datePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Open Date Picker"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.497"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.33" />

    <Button
        android:id="@+id/timePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Open Time Picker"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/datePicker" />

</androidx.constraintlayout.widget.ConstraintLayout>

Android API version: 10

Material Library version: 1.3.0-alpha04

Device: OnePlus 6T & Emulator in Android Studio

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the MainActivity example and reproduce the first-open delay for MaterialDatePicker and MaterialTimePicker on the listed device or emulator, using Material Library 1.3.0-alpha04 and Android API 10. Compare the cold-start and consecutive-click behavior, then identify the loading path responsible; done means both pickers open nearly instantaneously on the first request.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.