The Subtle Art of Making a Product Lightening Fast Performance == Quality 60% Speed, design & usability When leaving a 5 star review, 60% of the time the user mentions the speed, design or usability Google analysis on Play reviews, top 10 English speaking countries, last 365 days of reviews Firebase Performance Monitoring • Runs in production • Negligible overhead • Automatic and Custom traces • Automatic HTTP/S traffic metrics T ra ce • A report for a period of time with a well - defined beginning and end • Nominally has a duration • Also may contain "counters" for performance - related events during the trace A u t omat i c Tr ace s - n o cod ing ne ce ssa r y! • App Start (cold) • Time in foreground • Time in background A u t omat i c Tr ace s - A p p Sta r t ContentProvider.onCreate() Activity.onResume() But you might want something different! Counters • Associate a string/count value to a Trace • Typically better to measure ratios than absolute values • Abs value if you want to compare similar counters between traces cache_hit++ ca ch e _m i ss + + dropped_frames += 10 An idea for pseudo - automatic traces Implement Lifecycle Callbacks public class PerfLifecycleCallbacks implements Application ActivityLifecycleCallbacks { private static final PerfLifecycleCallbacks instance = new PerfLifecycleCallbacks (); private PerfLifecycleCallbacks () {} public static PerfLifecycleCallbacks getInstance () { return instance; } } Implement Lifecyclecallbacks private final HashMap < Activity , Trace > traces = new HashMap <>(); @Override public void onActivityStarted ( Activity activity) { String name = activity. getClass (). getSimpleName (); Trace trace = FirebasePerformance startTrace (name); traces. put (activity, trace); } @Override public void onActivityStopped ( Activity activity) { Trace trace = traces. remove (activity); trace. stop (); } Use Annotations import com.google.firebase.perf .FirebasePerformance; import com.google.firebase.perf .metrics.AddTrace; // Add the `@AddTrace` annotation above the method you want to trace @AddTrace ( name = " onCreateTrace ", enabled = true /* optional */ ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } Use Annotations val cache = ItemCache() val myTrace = Firebase.performance.newTrace (" test_trace ") myTrace. start() val item = cache.fetch(" item ") if (item != null) { myTrace .incrementMetric(" item_cache_hit ", 1) } else { myTrace .incrementMetric(" item_cache_miss ", 1) } A nd r o i d V i ta ls - get c lu e s fo r wh at t o mea sur e • New in the Google Play Console: • Performance - related stats • Slow rendering (jank) • Frozen frames Automatic HTTP/S transaction metrics • Response time • Payload size • Success rate • URL pattern yourcdn.com/*.jpg api.yourdomain.com/v1/users/* api.yourdomain.com/v1/users/*/history/* HTTP/S transaction metrics breakdown • App version • Device • Country • OS level • Carrier • Radio How HTTP/S monitoring works Bytecode manipulation (with ASM) URL url = new URL("https://firebase.google.com"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); URL url = new URL(“https://firebase.google.com”); HttpsURLConnection conn = (HttpsURLConnection) FirebasePerfUrlConnection.instrument(url.openConnection()); Decorator inside! How HTTP/S monitoring works dependencies { compile 'com.google.firebase:firebase - perf:11.0.2' } apply plugin: ' com.google.firebase.firebase - perf' Uses the Transform API