- Aug 11 2016
- j
Boosting app performance with reflectionless (de)serialization
by kevinzetterstrom
As any native app developer will tell you, API responsiveness and application performance are directly correlated with a positive user experience — meaning, when those things are running smoothly, your fans will be happy, and when they’re running less well, they notice. Because Vimeo’s app is so dependent on network requests, we investigated ways in which we could improve load time. While there were many areas in the request lifecycle that we examined, we focused on the parsing of JSON responses.
Gson is ON
The Vimeo Android app uses Retrofit for its networking layer and Gson for deserialization. One downside to this approach is that it can be quite slow, as Gson uses reflection to turn JSON into model objects. So to improve that deserialization time, we wanted to try removing that reflection. And we’re not the only ones who have realized how important this is: across industries, people are starting to recognize the cost of slow reflection.
In order to avoid reflection, we created custom Gson TypeAdapters. These allow us to control how data is parsed and provides us with a faster alternative. We have many models in our networking layer, and we chose a few to quantify the effect of reflection-less (de)serialization. The table below shows these models in terms of their data size.
| Model size (KB) | Model Type | Device | Method | Reflection (ms) | Custom TypeAdapter (ms) | Performance Gain |
|---|---|---|---|---|---|---|
| 2 | Comment | Nexus 9 | Deserialization | 40 | 40 | 0 |
| Serialization | 75 | 50 | -33% | |||
| 40 | CommentList | Nexus 9 | Deserialization | 475 | 430 | -10% |
| Serialization | 950 | 760 | -20% | |||
| 8 | Video | Nexus 9 | Deserialization | 135 | 115 | -15% |
| Serialization | 235 | 185 | -22% | |||
| 200 | VideoList | Nexus 9 | Deserialization | 1000 | 1100 | 10% |
| Serialization | 1000 | 1100 | 10% | |||
| 200 | VideoList | Samsung S2 | Deserialization | 2200 | 1900 | -14% |
| Serialization | 2000 | 1850 | -14% |
We used a high-end tablet for testing, knowing that if we saw gains there, lower-end devices would also benefit. Looking at the chart above, we can see that in many cases, primarily when the data is not as large, using custom TypeAdapters was faster than using reflection. The outlier was one of our heaviest models: on a high-end device such as the Nexus 9, reflection was faster than a custom TypeAdapter. But because profiling on a lower-end device showed us that we were still able to cut down on parsing time — and since not everyone has a top-shelf device — we decided it was still in our members’ best interests to use custom TypeAdapters.
STAG, yo
The models we used in the table above contained nested objects, and while it was pretty boilerplate, it amounted to 3K lines of additional code! We weren’t thrilled with the idea of writing all that code by hand, and one of our engineers had a great idea: why not generate it at compile time? Enter STAG. STAG stands for Speedy Type Adapter Generation, and it does just that.
STAG is an annotation processor. It works by looking for a specific annotation (GsonAdapterKey) on class member variables that you want to (de)serialize using Gson. If it finds this annotation on a member variable, it will create a TypeAdapter for that class, generating code for that member variable and any other annotated fields.
In our networking layer, we have abstract classes that use generics, so we made sure to accommodate for them. When you add the annotation to a concrete subclass, STAG will create a TypeAdapter for that class, thereby incorporating any annotated members of its parent — even those that are generic.
If you already use the Gson SerializedName annotation, taking advantage of this library is as simple as replacing that annotation with the GsonAdapterKey one. We were using SerializedName on many of our models, so incorporating STAG was fairly easy. If you’re not using the SerializedName annotation, simply add the annotation to the appropriate models.
Ready, set, deserialize
Want to get started? And improve overall app performance and user sentiment? STAG is open-sourced (https://github.com/vimeo/stag-java) and available now. No one should need to go through the headache of writing custom TypeAdapters, so for anyone using Gson, you can drop in this library and start raking in the benefits from performant, reflection-less (de)serialization.
- Mar 16 2016
- j
Two new open-source libraries to Vimeo-ize your Android app
by fuzzywarblz
Vimeo loves creators. Often, we’re talking about creators of the video variety, but today, we’re talking about the creators behind the creators — a.k.a., the coders. It’s no secret that we’ve got a pretty dope public API, and those open-source Objective-C libraries we released back in April are making iOS video app development easier.
Now, it’s Android’s turn.
Today we’re releasing two open-source libraries made specifically for all you Android devs: one for interacting with the Vimeo API and the other for handling Vimeo-related deep linking. So what’s it gonna be — blue pill or red pill? Red pill … duh.
Make friends with the Vimeo API using vimeo-networking-java
This retrofit-based Java library makes it easy as pie to interact with the Vimeo API in the context of a Java or Android application. You can authenticate users, fetch videos, categories, channels, and much much more. The library also includes response caching, object deserialization, account management, and network logging. To vouch for its stability, we’re currently using the library in our brand-new Android app.
Our goal is to give you, the developers, the power to build robust native applications which leverage all of the goodies people love most about Vimeo. With a few simple calls, you’ll have direct access to the entirety of our API catalog. Whether you want to build a clean app for viewing videos in the Tech Talks category, or an app for managing your personal Vimeo account, vimeo-networking’s got your back.
For a complete description of vimeo-networking functionality, check the developer docs.
Deep link anywhere in the app using vimeo-deeplink-android
Deep links are all the rage, but figuring out complex URI schemes can be a pain. That’s why we created vimeo-deeplink-android, which provides simple, one-line commands for deep linking into the Vimeo Android app.
- Want to open our video player to watch a specific video? We’ve got you covered.
- How about seamlessly diving into our curated Music category? Yup, we can handle that too. (The question is … can you?!)
Whether you’re trying to access a user, channel, or category, or just upload a video, we offer easy deep link integration so that you (or your team) can focus on the stuff that matters most to you.
For a complete list of our deep-link support, those developer docs have once again got you covered.
What next?
Let’s write some code.
Send us your feedback!
- Tweet at us: @vimeoapi
- Post on Stackoverflow with the tag vimeo-android
Are we speaking your (highly optimized and bug-free) language? Maybe there’s a job for you at Vimeo.
- May 6 2015
- j
The Video Hack Day: crank on some code with us May 9
by dashron
This Saturday, May 9, Vimeo is sponsoring a brand-new API event, appropriately dubbed “Video Hack Day.” This all-day event takes place May 9 at General Assembly in NYC. Stop by to hear fascinating keynotes from members of the tech community. And when the talks stop, stick around and build some awesomely innovative video apps, websites, tools, and toys.
Should you attend, swing by the Vimeo table (a.k.a. the “cool” table). We’ll be giving out high-fives and three free months of Vimeo PRO to anyone who stops by to say “yo.” But that’s not the only thing we’re giving away — at the end of the night, the best Vimeo API integration made at the event will take home a video-enabled quadcopter.
Space is limited, so register now! We’re psyched to see what you build…
(Source: vimeoapi)
