Trimming Unused Dependencies via Package and Module Graphs
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing techniques for removing unused portions of applications, such as tree-shaking, often fail to accurately identify and eliminate dynamic dependencies, leading to incomplete removal and potential sharing issues between applications.
Innovation Solution
The use of package and module graphs to traverse and identify unused dependencies at compile time, allowing for precise inclusion or exclusion of dependencies in the application at deployment time, preserving module identity and eliminating the need for manual trimming.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Quantity of substance
If native compilers statically analyze libraries and eliminate uncalled code, then application size is reduced, but dynamic references cannot be handled and module identity is lost
Solution Approach 1:
The patent introduces an intermediary system that bridges static analysis and dynamic reference handling. Package graphs and module graphs serve as intermediary data structures that capture both static dependencies and dynamic reference patterns, allowing the compiler to make informed decisions about code elimination without losing module identity or breaking dynamic references.
Solution Approach 2:
The patent performs preliminary actions by constructing package graphs and module graphs before the actual tree-shaking process. These graphs pre-identify all potential dependencies including dynamic ones, so that when code elimination occurs, no critical dynamic references are accidentally removed. This preliminary analysis phase separates the identification of dependencies from the elimination process.
2Measurement precision
If pre-compilers use heuristics to identify dynamic references, then some dynamic dependencies are found, but the heuristics are incomplete and require additional developer effort
Solution Approach 1:
The patent segments the dependency analysis into two distinct graphs: package graphs for static package-level dependencies and module graphs for fine-grained module-level dependencies including dynamic references. This segmentation allows each graph to specialize in its domain, achieving comprehensive coverage without requiring a single complex heuristic system. The module graph specifically captures dynamic references that heuristics might miss.
Solution Approach 2:
The patent adds another dimension to dependency analysis by introducing the module graph layer beneath the package graph. While package graphs operate at one level of abstraction, the module graph provides a finer-grained dimension that captures module-level dynamic references. This dimensional addition enables precise identification of dynamic dependencies without overwhelming complexity.
3Device complexity
If code is merged into a single module, then static analysis is simplified, but module identity is eliminated and sharing between applications is prevented
Solution Approach 1:
The patent maintains segmentation at the module level throughout the analysis and compilation process. Rather than merging all code into a single module, the system preserves module boundaries and uses the module graph to track dependencies between distinct modules. This segmentation enables both simplified analysis (through graph-based dependency tracking) and module identity preservation (for sharing and servicing outside applications).
Data Source
AI summary
Techniques are described herein that are capable of trimming unused dependencies using a package graph and a module graph. For instance, the package graph and the module graph may be traversed to determine whether dependencies of an application are used during execution of the application. A version of the application may be configured to include the dependencies that are used and to not include the dependencies that are not used. For instance, the version of the application may be configured to be utilized at deployment time.


