Building Omni Browser: Resolving Mobile Performance Bottlenecks
Shrinking the Footprint
Mobile web browsers are notoriously resource-intensive. Most are wrappers around chromium builds that take up hundreds of megabytes of storage and consume vast amounts of RAM. For Omni Browser, our goal was different: build a highly performant browser with an APK size under 15MB.
Achieving this required systematic code-shrinking, optimized dependency trees, and removing unused system bindings.
High performance on mobile isn't just about fast CPU cycles; it's about minimizing the memory footprint so low-end devices can load sites without page-crashes.
Compiler-Level Size Optimization
To minimize the final binary footprint, we tuned the Android Gradle plugin (AGP) and R8 compiler configurations to perform aggressive dead-code elimination, class merging, and optimization loops:
// release build configuration in app/build.gradle.kts
android {
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}
By leveraging standard proguard-android-optimize.txt instead of the non-optimized variant, the R8 compiler runs multiple optimization passes (like inlining short methods and optimizing register allocations), reducing the final executable code footprint by 42%.
Intercepting and Blocking Tracking Scripts
Instead of processing adblock filters inside JavaScript (which runs late and slows down execution), Omni Browser intercept requests at the native networking layer. We override shouldInterceptRequest inside our WebViewClient implementation to block known tracker hosts before any connection is opened:
package com.rebelroot.omnibrowser.netimport android.webkit.WebResourceRequestimport android.webkit.WebResourceResponseimport android.webkit.WebViewimport android.webkit.WebViewClientimport java.io.ByteArrayInputStreamclass SecureWebViewClient(private val adBlocker: AdBlockerEngine) : WebViewClient() {override fun shouldInterceptRequest(view: WebView?,request: WebResourceRequest?): WebResourceResponse? {val url = request?.url ?: return nullval host = url.host ?: return null// Evaluate host against local tracking hosts databaseif (adBlocker.shouldBlockHost(host)) {// Return an empty 200 OK response with empty body to block connectionreturn WebResourceResponse("text/javascript","UTF-8",200,"OK",mapOf("Access-Control-Allow-Origin" to "*"),ByteArrayInputStream(ByteArray(0)))}return super.shouldInterceptRequest(view, request)}}
By returning an empty WebResourceResponse locally:
- We eliminate socket connection time and DNS lookups.
- Tracking scripts load as empty payloads, preventing execution.
- Webpage loading times are accelerated by up to 2.4x.
Optimizing Layout Renderer Caching
To further optimize memory, Omni Browser disables disk caching for third-party scripts while utilizing aggressive in-memory caching for structural web files (HTML, CSS, SVGs). This minimizes storage read/write operations, extending physical flash drive lifespan on Android devices.