Modern software systems rely on a multitude of third-party dependencies. This large-scale code reuse reduces development costs and time, and it poses new challenges with respect to maintenance and security. Techniques such as tree shaking or shading can remove dependencies that are completely unused by a project, which partly address these challenges. Yet, the remaining dependencies are likely to be used only partially, leaving room for further reduction of third-party code. In this paper, we propose a novel technique to specialize dependencies of Java projects, based on their actual usage. For each dependency, we systematically identify the subset of its functionalities that is necessary to build the project, and remove the rest. Each specialized dependency is repackaged. Then, we generate specialized dependency trees where the original dependencies are replaced by the specialized versions and we rebuild the project. We implement our technique in a tool called DepTrim, which we evaluate with 30 notable open-source Java projects. DepTrim specializes a total of 343 (86.6%) dependencies across these projects, and successfully rebuilds each project with a specialized dependency tree. Moreover, through this specialization, DepTrim removes a total of 60,962 (47.0%) classes from the dependencies, reducing the ratio of dependency classes to project classes from 8.7x in the original projects to 4.4x after specialization. These results indicate the relevance of dependency specialization to significantly reduce the share of third-party code in Java projects.
翻译:现代软件系统依赖大量的第三方依赖。这种大规模代码复用降低了开发成本和时间,但也带来了维护和安全方面的新挑战。诸如树摇或阴影遮蔽等技术可以移除项目完全未使用的依赖,从而部分解决这些挑战。然而,剩余的依赖很可能仅被部分使用,这为进一步减少第三方代码留下了空间。在本文中,我们提出一种基于实际使用情况对Java项目依赖进行特化的新技术。对于每个依赖,我们系统地识别其构建项目所需的功能子集,并移除其余部分。每个特化后的依赖被重新打包。然后,我们生成特化的依赖树,其中原始依赖被特化版本替换,并重新构建项目。我们在一个名为DepTrim的工具中实现了我们的技术,并使用30个著名的开源Java项目对其进行了评估。DepTrim在这些项目中总共特化了343个(86.6%)依赖,并成功使用特化依赖树重建了每个项目。此外,通过这种特化,DepTrim从依赖中移除了总计60,962个(47.0%)类,将依赖类与项目类的比例从原始项目中的8.7倍降低到特化后的4.4倍。这些结果表明,依赖特化对于显著减少Java项目中第三方代码占比具有重要意义。