Google I/O 2010 - Writing zippy Android apps

Google for Developers · 73K views · 2010 · 57:38

Open on YouTube

Software performance & optimizationSoftware practice, open source & careerstalkdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about janky UIs, slow database or disk I/O, and profiling Android apps, since it explains why flash writes and main-thread work cause lag.

Recommended by 6 people across 6 different months, 2010 to 2014.

What it is

A Google I/O 2010 session in the Android 201 track where Brad Fitzpatrick shares tips and war stories on making Android apps fast and responsive. It covers avoiding ANRs and event loop stalls, fast start-up, minimizing database I/O, and the tools used to find performance problems across the system.

What people said

Strong rec Yoni Samlan · 2010-10 · Stack Overflow · on “best way to implement a list of special UI elements?”

That view is fairly straightforward, and performancewise should be no problem at all as long as you use a ListView [LINK] with a ListAdapter [LINK] that properly utilizes view recycling and the holder pattern (see the Android API Demos List14 demo for a good example [LINK] of that). That means your row view will only be inflated (the expensive part) a few times, and after that you'll simply be populating an existing row that has moved off screen with new information to be rerendered, so in reality there end up being only 6 or 7 instances of your row view in memory, not 40. Caveats: Make sure you're not doing anything that blocks the UI thread in your adapter's view inflation/population, like

Recommends Jeremy Edwards · 2010-09 · Stack Overflow · on “Is there any efficient way to make Android database query faster?”

You should never read from the database in the UI thread. Use a background thread via AsyncTask or using regular threading. This will fix the UI lag issue your having. Making the database read faster will help with bringing the data faster to the user but it's even more important that the fetching of the data does not block the user from using the app. Check out the Following Links: Painless Threading in Android [LINK] [this video]

Recommends dstefanox · 2010-12 · Stack Overflow · on “I want to get the time of starting an application”

In video from Google io 2010 you have explanation how you can use certain tools to profile applications. Take a look at the [this video] . Related projects and tools are at [LINK]

Recommends CommonsWare · 2011-02 · Stack Overflow · on “Random long IO pauses when writing data periodically”

Why is this happening? Welcome to flash. I'm no expert in file IO but I know the fast IO operation times indicate the data hasn't actually been written to disk yet and the big pauses are probably buffers being flushed. Probably not. Most Android devices use the YAFFS2 file system, which does not buffer data too much, as I understand it. However, they do have a per-partition write lock, so your pauses are probably when something else is writing to flash. As more Android devices (e.g., Nexus S) run the ext4 file system, then flushing/syncing becomes important [LINK] . Also, bear in mind that flash write speeds will vary by a variety of other factors, such as how full the file system is, the st

Recommends louielouie · 2012-03 · Stack Overflow · on “How to verify SQL queries in Android”

You can use adb shell . Then inside of the shell, you can use sqlite3 . Read this for more details: [LINK] Here's a relevant excerpt: From an adb remote shell, you can use the sqlite3 command-line program to manage SQLite databases created by Android applications. The sqlite3 tool includes many useful commands, such as .dump to print out the contents of a table and .schema to print the SQL CREATE statement for an existing table. The tool also gives you the ability to execute SQLite commands on the fly. To use sqlite3, enter a remote shell on the emulator instance, as described above, then invoke the tool using the sqlite3 command. Optionally, when invoking sqlite3 you can specify the full pa

Recommends Alex K · 2014-12 · Stack Overflow · on “App is slower after renaming package”

It's just a different name for the package. I don't think it should be ANY slower due to a certain name. You can try completely removing the app from your test device (through the settings) which will wipe all traces of it, and then installing it again. A simple package name change shouldn't have an impact like that. You can check this out for a cool talk on how to write quick android apps: [this video]

Cites Ben L. · 2010-06 · Stack Overflow · on “Does Android AsyncTaskQueue or similar exist?”

I read somewhere (and have observed) that starting threads is slow. I always assumed that AsyncTask created and reused a single thread because it required being started inside the UI thread. The following (anonymized) code is called from a ListAdapter's getView method to load images asynchronously. It works well until the user moves the list quickly, and then it becomes " janky [this video] ". final File imageFile = new File(getCacheDir().getPath() + "/img/" + p.image); image.setVisibility(View.GONE); view.findViewById(R.id.imageLoading).setVisibility(View.VISIBLE); (new AsyncTask<Void, Void, Bitmap>() { @Override protected Bitmap doInBackground(Void... params) { try { Bitmap image; if (!imageFil

Cites CommonsWare · 2010-09 · Stack Overflow · on “Performance of app on Android Phone Emulator vs Actual Device?”

From a CPU standpoint, the emulator tends to be slower than actual hardware, presumably due to the overhead of converting ARM bytecodes to x86 ones on the fly. From a graphics standpoint, the emulator tends to be dramatically slower than actual hardware, because the emulator lacks hardware graphics acceleration (regardless of the quality of the host computer's video card). From a disk I/O standpoint, the emulator tends to be faster than actual hardware, particularly on write operations. Flash writes can be very slow, depending on a wide range of criteria (wear leveling, percentage of the flash storage that is in use, etc.). Brad Fitzpatrick covered this topic in his Writing zippy Android app

Cites smith324 · 2010-12 · Stack Overflow · on “Which is faster to load in android, a file from external storage or a file from internal storage?”

@Chris Stratton Ah yes you are correct. Usually I'm more concerned with write speeds because they are slower than the reads. For those interested Brad Fitzpatrick (wrote StrictMode) did a presentation at Google I/O last year on (partially) this topic of disk speeds. [this video]