Muzeel: A Dynamic JavaScript Analyzer for Dead Code Elimination in Today's Web

Tofunmi Kupoluyi, Moumena Chaqfeh, Matteo Varvello, Waleed Hashmi, Lakshmi Subramanian, Yasir ZakiarXiv 2021

TL;DR

Muzeel is a dynamic JavaScript analyzer that uses an automated "interaction bot" to identify and strip away unused code (dead code) from modern web pages. By emulating complex user interactions and handling event dependencies, it reduces page sizes by 60% and speeds up mobile page loads by up to 30%.

What Problem Does This Paper Address?

Modern web development relies heavily on massive, general-purpose JavaScript libraries. While convenient for developers, this practice leads to significant "web bloat": browsers often download and parse thousands of functions that are never actually executed.

This unused "dead code" is particularly punishing for users on low-end mobile devices and slow networks, as the browser must still process the entire script before the page becomes interactive. Existing solutions fall short: static analysis struggles with JavaScript’s dynamic nature, and previous dynamic tools often stop analyzing once the page finishes loading, mistakenly labeling code triggered by user interactions (like clicking a menu) as "dead."

Methods

The authors propose Muzeel (Arabic for "eliminator"), a system designed to run at the CDN (Content Delivery Network) level. Its workflow consists of three main phases:

  1. Pre-processing: Muzeel instruments the page's JavaScript, assigning a unique ID to every function and adding a small snippet of code that logs to the console whenever a function is called.
  2. Dead Code Discovery: This is the core innovation. Muzeel uses an Interaction Bot to load the page in an automated browser. The bot identifies all interactive elements (buttons, links, etc.) using XPaths. Crucially, it uses a breadth-first search algorithm to handle event dependencies. For example, it knows it must click a "More" menu to reveal and test the sub-buttons hidden within it.
  3. Elimination: After the bot has triggered every possible interaction, Muzeel reviews the logs. Any function ID that never appeared in the console is deemed "dead" and is stripped from the final JavaScript files served to the user.
Figure 1: Muzeel’s architecture with the main pro- cesses.

Datasets

The researchers evaluated Muzeel using:

  • 40,000 popular web pages from Alexa’s top 1M list to quantify the prevalence of dead code.
  • A subset of 200 pages for rigorous performance benchmarking.
  • Test Hardware: A range of Android devices, from the low-end Redmi Go and Samsung J3 to the high-end Samsung S10, tested across emulated 3G, LTE, and LTE+ networks.

Key Insights and Ideas

  • The 70/60 Rule: The study found that on a median web page, 70% of JavaScript functions are unused, and removing them reduces the total page size by 60%.
  • Interactivity is the Blind Spot: Most optimization tools fail because they don't account for code that only runs when a user interacts with the page. Muzeel’s bot-driven approach ensures these "interaction-only" functions are preserved.
  • Handling Hidden Elements: Many page elements are "hidden" until a specific action occurs (see Figure 2 below). Muzeel’s dependency-aware bot ensures these hidden paths are explored, preventing the accidental deletion of functional code.
Figure 2: An example showing a hidden page element
  • CDN-Level Efficiency: Because 99% of a page's optimized JavaScript remains valid for at least a week, Muzeel only needs to re-analyze pages periodically, making it a viable background service for CDNs.

Key Results

  • Significant Speedups: On low-end phones under 3G networks, Muzeel improved Page Load Time (PLT) by 30%. High-end phones saw a 25% improvement.
  • Better User Experience: The Speed Index (a measure of how quickly the visual parts of a page appear) improved by 21-23%.
  • Size Reduction: Muzeel achieved a median reduction of 0.8 MB per page.
  • Superiority over State-of-the-Art: When compared to Lacuna (a prominent academic dynamic analyzer), Muzeel improved the median PLT by over 7 seconds while maintaining higher structural and functional similarity to the original pages.

Limitations and Future Work

  • Third-Party Constraints: Muzeel cannot currently optimize copyrighted third-party scripts (like Google Analytics) unless the website owner hosts them locally, as the CDN lacks the authority to modify external files.
  • Analysis Overhead: It takes between 5 and 20 minutes to fully analyze a single page. While acceptable for a CDN background process, it is not yet fast enough for real-time optimization of rapidly changing content.
  • Complex State Machines: While the bot handles event dependencies well, extremely complex Single Page Applications (SPAs) with deep internal states may still present edge cases where code is incorrectly identified as dead.

Summary updated

Abstract

JavaScript contributes to the increasing complexity of today's web. To support user interactivity and accelerate the development cycle, web developers heavily rely on large general-purpose third-party JavaScript libraries. This practice increases the size and the processing complexity of a web page by bringing additional functions that are not used by the page but unnecessarily downloaded and processed by the browser. In this paper, an analysis of around 40,000 web pages shows that 70% of JavaScript functions on the median page are unused, and the elimination of these functions would contribute to the reduction of the page size by 60%. Motivated by these findings, we propose Muzeel (which means eliminator in Arabic); a solution for eliminating JavaScript functions that are not used in a given web page (commonly referred to as dead code). Muzeel extracts all of the page event listeners upon page load, and emulates user interactions using a bot that triggers each of these events, in order to eliminate the dead code of functions that are not called by any of these events. Our evaluation results spanning several Android mobile phones and browsers show that Muzeel speeds up the page load by around 30% on low-end phones, and by 25% on high-end phones under 3G network. It also reduces the speed index (which is an important user experience metric) by 23% and 21% under the same network on low-end, and high-end phones, respectively. Additionally, Muzeel reduces the overall download size while maintaining the visual content and interactive functionality of the pages.
BibTeX
@misc{kupoluyi2021muzeel,
  author = {Tofunmi Kupoluyi and Moumena Chaqfeh and Matteo Varvello and Waleed Hashmi and Lakshmi Subramanian and Yasir Zaki},
  title = {{Muzeel: A Dynamic JavaScript Analyzer for Dead Code Elimination in Today's Web}},
  year = {2021},
  eprint = {2106.08948},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2106.08948},
}

Loading related content...

Figure