DEV Community

Danyal Muneer
Danyal Muneer

Posted on AI-assisted

We removed 82 MB of native code that nothing imported

Our Android APK was carrying two native libraries that no JavaScript file used anymore.

  • librnskia.so: 41 MB across 4 ABIs. Skia stayed in package.json after we replaced our charts with plain react-native-svg rings and Views.
  • WebRTC (libjingle_peerconnection_so.so): 41 MB across ABIs. It was left over from a voice path we had already retired. Worse, it was being dlopen'd 574 ms into every cold start, before the first frame, for code nothing imported.

The lesson

Autolinking compiles a library's native code into the APK whether or not any JS imports it. A package you "parked" in package.json for later is not free. You pay for it in download size and, sometimes, in startup time.

How we found them

  1. Break the APK down by ABI, library and asset. We have a small script (yarn perf apk) that unzips the build and sorts every .so by size. Two 41 MB entries for features we no longer shipped stood out immediately.
  2. Watch what loads at startup. A second script (yarn perf soload) reads logcat during a cold start and lists every .so that loads, with a timestamp. That's how WebRTC showed up at 574 ms.
  3. Remove it and make sure it stays removed. We deleted the packages and added an ESLint no-restricted-imports entry for each one, with the reason in the message, so nobody adds them back without reading why.

Bonus: BlurView on Android

On iOS, BlurView is a hardware-accelerated UIVisualEffectView. On Android it re-samples the whole view tree into a bitmap and blurs it every frame for as long as it is mounted.

Our floating action menu used a full-screen blur and measured p50 51 ms and p95 101 ms per frame, with 8.3% of frames over 100 ms. It was the worst interaction in the app. Replacing the blur with a flat scrim on Android (keeping the blur on iOS) fixed it.

Takeaways

  • Audit your APK by library, not just total size.
  • Check which native libraries load before your first frame.
  • Remove unused native packages and lint against them coming back.
  • Gate full-screen blur to iOS.

I'm building Finovaa, an AI budgeting coach for iOS and Android, currently in store review.

Top comments (1)

Collapse
 
yonto profile image
Yonto Player •

The soload logcat trick is a nice one, I hadn't thought of timing the dlopen at cold start. On the native side we build our own FFmpeg and libVLC, LGPL-only and with no video encoders, which keeps both the size and the licence in check. A per-ABI size breakdown like your yarn perf apk is what keeps that honest over time.