Show HN:Rev-dep – 比 Go 中的 knip.dev 替代版本快 20 倍
探索 rev-dep,一个 Go 构建的死代码检测工具,比 knip.dev 快 20 倍。为不断壮大的软件团队缩短构建时间并清理代码库。
Mewayz Team
Editorial Team
每个成长中的软件团队的隐性税收
每个生存足够长的软件项目最终都会面临同样的悄然危机:代码库的增长速度超出了团队的理解速度。没有人调用的函数、为 2022 年发布的功能创建的导出并被悄悄弃用、存在于磁盘上但从未到达浏览器的组件。这不是马虎——这是物理学。团队行动迅速,需求不断变化,而且熵是无情的。问题不在于你的代码库是否有死代码。问题是你现在要花多少钱。
根据 Google 工程生产力团队的研究,开发人员平均花费 42% 的编码时间来阅读和理解现有代码,而不是编写新功能。当现有代码包含数千行不再有任何用途时,该百分比甚至会更高。对于一个由十名工程师组成的团队来说,这实际上是四名全职员工没有做任何富有成效的事情——不是因为他们懒惰,而是因为他们的工具跟不上软件老化的速度。
这就是为什么基于 Go 和 Rust 等系统语言构建的新一波开发者工具在工程界引起了真正的兴奋。像 Rev-dep 这样的工具(一种反向依赖分析器,声称运行速度比流行的基于 JavaScript 的 knip.dev 快 20 倍)代表的不仅仅是渐进式改进。它们标志着我们对如何衡量开发过程本身的根本性重新思考。
反向依赖分析实际上是做什么的
在理解为什么速度如此重要之前,了解依赖关系分析工具实际上在做什么会有所帮助。在 JavaScript 或 TypeScript 项目中,每个文件都从其他文件导入。从模块导出的每个函数、类或常量都会创建潜在的依赖项 - 代码库的其他部分可能依赖的东西。 “反向”依赖分析翻转了这个观点:它不是问“这个模块依赖什么”,而是问“什么依赖这个模块?”
如果第二个问题的答案是“什么也没有”,那么您就发现了死代码。不进口任何东西的出口就是浪费。一个无所谓的功能是具有月利率的技术债务。反向依赖工具系统地遍历整个项目图,映射模块之间的每个关系,并显示没有入站连接的节点。结果是对代码库中可以安全删除的所有内容进行精确审核。
Knip.dev 在 JavaScript 和 TypeScript 项目中做得很好,并且在社区中受到广泛尊重。但它是用 JavaScript 编写的,这意味着它运行在 Node.js 上,这意味着它在进行大规模文件系统遍历和符号分析时继承了 Node 的所有单线程性能限制。对于一个有 500 个文件的项目来说,这已经足够了。对于一个包含 50,000 个文件的项目(这种为真正的企业 SaaS 产品提供支持的单一存储库),分析可能需要几分钟的时间。以现代 CI/CD 管道运行的节奏来看,分钟是一个破坏性因素。
为什么 Go 改变了计算方式
Go 是从头开始设计的,正是为了满足依赖性分析所需的工作负载类型:快速文件 I/O、出色的并发原语和最小的运行时开销。 Node.js 在单个线程上一次处理一个任务并依赖回调并承诺伪造并行性,而 Go 可以生成数千个 goroutine,这些 goroutine 在所有可用的 CPU 核心上真正并行执行。对于涉及读取数百个文件、解析其 AST 以及构建符号关系图的任务,这种架构差异会直接转化为挂钟性能。
Rev-dep 声称的 20 倍加速并不神奇,而是当您将正确的语言与正确的问题相匹配时所发生的事情。 Go 的编译性质也意味着没有 JIT 预热惩罚。从冷启动到完成分析,Go 二进制文件都以接近峰值的速度运行
Frequently Asked Questions
What makes Rev-dep faster than knip.dev?
Rev-dep is built in Go, a compiled systems language optimized for concurrency and raw execution speed, whereas knip.dev runs on Node.js. This architectural difference allows Rev-dep to analyze dependency graphs and detect dead code up to 20x faster. For large monorepos or complex codebases — like the 207-module architecture powering Mewayz's business OS at app.mewayz.com — that performance gap translates into real time saved on every CI run.
How much dead code does a typical growing project accumulate?
Studies and anecdotal reports from engineering teams suggest that mature codebases can carry anywhere from 10% to 35% unused or unreachable code. The problem compounds as teams scale — features get deprecated, APIs change, and modules are abandoned without cleanup. Platforms like Mewayz, which consolidates over 207 business modules into a single $19/mo operating system, rely heavily on systematic dead code detection to keep the codebase lean and maintainable.
Is Rev-dep suitable for teams that don't use JavaScript or TypeScript?
Rev-dep is currently focused on JavaScript and TypeScript ecosystems, making it a direct alternative to knip.dev for those environments. Support for additional languages may expand as the project matures. If your team builds web-based products or SaaS tools — similar to how Mewayz delivers its full business OS at app.mewayz.com — and your stack is JS/TS-heavy, Rev-dep is well worth evaluating as part of your developer toolchain today.
Can I integrate Rev-dep into my existing CI/CD pipeline?
Yes. Rev-dep is designed as a CLI tool, making it straightforward to drop into any CI/CD pipeline alongside your existing linting and testing steps. Its speed advantage is especially valuable in automated pipelines where faster feedback loops reduce developer wait times. Whether you're running a lean startup or managing a full-featured platform like Mewayz's $19/mo business OS, integrating dead code analysis into your pipeline helps enforce codebase hygiene at every merge.
Related Posts
获取更多类似的文章
每周商业提示和产品更新。永远免费。
您已订阅!