#Android Development: #Java #Threads, #Video Frame Timing, #Tango, training programmers
Posted on June 19th, 2015
Grubhub @ 5 Bryant Park, 15th Floor, NY
Four speakers talked about different aspects of programming/development.
In the first presentation, Jamie McDonald @SoundCloud talked about how #RxJava uses a new paradigm in Android for managing asynchronous processing threads.
Android runs all UI processing on the main the main thread, so processes requiring large amounts of resources are better executed on separate threads so as not to impact the user interactions. There are several methods for starting threads and broadcasting the output. These include:
- Runnable classes
- IntentService for background processes.
- AsyncTask which perform tasks by doInBackground with a callback.
Of these, the async task may have the most straightforward syntax, but lack error handing or a good ways to schedule tasks. For instance, a series of ordered tasks must be coordinated in nested async callbacks. Generally, with these methods the execution order of tasks may be hard to control as the operating system has evolved from serial execution to thread pools and back to serial as phones have moved from single to multiple processors.
RxJava (and RxAndroid) adds to this toolkit using a reactive programming framework developed originally by Netflix. It includes a library for observable abstractions with some functional programming. Everything is represented as a stream receiving observables and outputting to subscribers.
- An observable receives and operates on objects.
- A subscriber states an interest in receiving events and determinates what to do with the outputs or errors
- A scheduler links observables and subscribers and specifies which threads handle which tasks.
Jamie, presented code snippets illustrating an observer, a subscriber and a scheduler. He also talked about some of the most commonly used Stream Operators:
- Flatmap – takes source and maps to another output
- OnErrorResumeNext – recover if something goes wrong
The scheduler can also be used to create a single event bus which puts items in a queue and handles errors and outputs. This can prove especially useful if you change the main screen in which case you merely subscribe to an event on the scheduler’s queue.
But RxJava is new so there are still some issues: unit-test debugging may be challenging for long call chains; there is asteep learning curve with new concepts (e.g. backpressure if the observer is emitting more outputs than can be called by the subscriber). He noted that RxJava still requires code to handle when the orientation of the phone changes from portrait to landscape or vice versa.
In the second talk, Jason Sendros @Facebook talked about the synchronizing the display refresh rate with the animation frame update rate. The standard for screen refresh is 60 frames per second (17 ms), so the software should render its image in less than 17ms.
So, what happens when you miss a frame? Nothing initially. The previous frame is redisplayed and the screen starts its next refresh delay. What happens if you miss a second frame? The display appears jerky or does not scroll smoothly.
How do you detect problems and to fix them? There are several tools/methods to diagnose and fix the problem:
- abd shell dumpsys gfxinfo: information on a per frame basis, but cannot be used in production
- choreographer: (available after JellyBean OS) gives you the vsync time stamp. So, if you go over 33ms, you can use choreographer to disable the frame output.
- Maxframetime is a good diagnostic metric that measures the percent of time spent in buckets: % of time with 0 dropped frames, 1 dropped frames, etc.
- Systrace allows you to locate the most expensive worker in each frame. It is superlight so it can run on a user’s device without impacting performance.
- Automated testing can be used to look inside high level categories.
He recommended frequent us of microbenchmarks (at Facebook, they will closely monitor the cost of notification for dataset changes) to prevent performance from regressing as the software upgrades are made.
Testing is challenging since one must balance stability of test results (replicability) and performance in the real-world (accuracy).
The meetup was concluded by two lighting talks. In the first, Matthew Davis talked about project Tango which is a stack of sensors supplementing the standard functionality of android devices. Sensors include
- A higher resolution camera
- motion tracking camera
- IR depth sensor
- more RAM
The sensors are designed to allow geolocation indoors using motion tracking, area learning, and depth perception to create a visual inertial odometer using key visual markers.
Sensors collect data which is stored in a database, so the system learns about your environment over time. It’s database learns if you have been in the area before and will update the information. Data files can also be transmitted so you can coordinate activities with others (an example is a community cube stacker game in which several players build a common object a la Minecraft).
Qualcomm is designing a hardware set for phones.
Amy Quispe@Coalition4Queens talked about their project, #AccessCode to teach local, disadvantaged students how to code. Students generally do not have programming backgrounds.
She presented two apps made by students during their 8 week Android course:
- 4 function + scientific calculator
- Meme-ify – make memes from pictures and background info with text markup that can be shared on social media.
She encouraged audience members to be instructors in the project.