[论文解读] API Beauty is in the eye of the Clients: 2.2 Million Maven Dependencies reveal the Spectrum of Client-API Usages
本研究分析了94个流行Java库在Maven Central中220万个依赖项,发现尽管大多数API类型至少被一个客户端使用,但仅一小部分核心类型占据了绝大多数客户端的使用量。研究通过揭示使用量的连续谱系,解决了Hyrum定律与实证观察之间的矛盾:大多数API使用量极低,但随着客户端数量增加,即使罕见元素也会被采用。这使得API维护者能够优先维护和文档化核心元素。
Hyrum's law states a common observation in the software industry: "With a sufficient number of users of an API, it does not matter what you promise in the contract: all observable behaviors of your system will be depended on by somebody". Meanwhile, recent research results seem to contradict this observation when they state that "for most APIs, there is a small number of features that are actually used". We investigate this seeming paradox between the observations in industry and the research literature, with a large scale empirical study of client API relationships in one single ecosystem: Maven Central. We study the 94 most popular libraries in Maven Central, as well as the 829,410 client artifacts that declare a dependency to these libraries and that are available in Maven Central, summing up to 2.2M dependencies. Our analysis indicates the existence of a wide spectrum of API usages, with enough clients, most API types end up being used at least once. Our second key observation is that, for all libraries, there is a small set of API types that are used by the vast majority of its clients. The practical consequences of this study are two-fold: (i) it is possible for API maintainers to find an essential part of their API on which they can focus their efforts; (ii) API developers should limit the public API elements to the set of features for which they are ready to have users.
研究动机与目标
- 解决Hyrum定律(所有可观测行为都会被使用)与研究显示仅一小部分API功能实际被使用之间的明显矛盾。
- 调查大规模真实世界生态系统(Maven Central)中客户端-API的使用模式谱系。
- 在聚焦常用API元素的前提下,确定API维护工作量与支持客户端数量之间的权衡。
- 为API开发者提供可操作的见解,以在保持广泛客户端兼容性的同时减少公开表面面积。
- 探索仅维护API类型的一小部分即可支持大多数客户端的可行性。
提出的方法
- 截至2018年9月,从Maven依赖图(MDG)中收集了829,410个客户端工件和5,225个库版本。
- 通过静态字节码分析检测实际的API使用情况,区分声明依赖与运行时使用。
- 分析每个API所有版本的使用模式,识别累积使用量,随后聚焦于最流行版本。
- 将“Core_n”定义为支持n%客户端所需的最小API类型集合,使用灭绝序列测量影响。
- 通过统计分析量化在94个库中,零个、少数或大多数客户端使用的API类型比例。
- 通过三位研究人员的手动审查验证结果,并公开所有数据和代码以确保可复现性。
实验结果
研究问题
- RQ1Maven Central中声明的依赖在多大程度上实际导致了运行时API使用?
- RQ2在库的最流行版本中,有多少API类型至少被一个客户端使用?
- RQ3占大多数客户端使用量的API类型占比是多少,且该比例在不同库之间如何变化?
- RQ4是否可以通过仅维护API类型的一小部分来支持大量客户端?
- RQ5反射或动态调用的存在如何影响静态分析在检测API使用时的准确性?
主要发现
- 41.13%的声明依赖在字节码级别未导致任何实际API使用,表明声明与运行时使用之间存在显著差距。
- 对于每个库的最流行版本,所有公共API成员至少被一个客户端使用,证实了在大规模场景下Hyrum定律成立。
- 在超过一半的94个库中,仅需12%的API类型即可支持75%的客户端,表明存在一个频繁使用的元素核心。
- 通过聚焦支持90%的客户端而非全部客户端,像gson:2.3.1这样的库的迁移工作量可从162个API类型减少至20个(占12%)。
- 当客户端基数足够大时,即使罕见或特殊的API类型最终也会被至少一个客户端使用,支持Hyrum定律。
- 客户端代码中反射的使用率较低(≤0.47%的方法),表明在此上下文中静态分析在检测实际API使用方面是可靠的。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。