使用虚拟文件系统,2小时以上的Android构建任务可以缩短至15分钟。
SourceFS: A 2h+ Android build becomes a 15m task with a virtual filesystem

原始链接: https://www.source.dev/journal/sourcefs

## SourceFS:革新设备开发 SourceFS 是一种新型高性能虚拟文件系统,旨在大幅提升复杂设备代码库(如智能手机和电动汽车,通常超过 5 亿行代码)的软件开发速度。它解决了代码检出缓慢和构建时间过长等开发人员面临的主要痛点,并减轻了 CI 资源的压力。 与传统的构建系统不同,SourceFS 能够以极小的开销无缝集成到现有工作流程中。它虚拟化整个代码库,仅在需要时才物化文件——将检出速度提高 10 倍以上,并将磁盘使用量减少 83%。通过智能缓存和构建步骤回放,构建速度加快高达 9 倍,涵盖从编译到打包的整个过程。 结果非常显著:**构建速度快 9 倍,计算成本降低 14 倍,磁盘空间减少 83%。** SourceFS 通过新颖的算法、高级虚拟化和基于 Rust 的后端实现这一目标。它通过解决整个开发过程(而不仅仅是其中的一部分)来超越构建系统迁移和编译器包装器等替代方案。该团队正在积极扩展对更多操作系统的支持,并进一步优化性能,旨在改变设备软件开发。

## SourceFS:更快的构建速度,基于虚拟文件系统 SourceFS是一个新的虚拟文件系统,旨在大幅提升构建速度,尤其适用于Android等大型代码库。据报道,该系统通过缓存和重放构建步骤,与Git、Repo和标准Linux环境等现有工具集成,将Android构建时间从超过2小时缩短到仅15分钟。 SourceFS的灵感来自Google内部系统(SrcFS/Piper)和Meta(EdenFS),旨在为更广泛的团队带来类似的性能优势。讨论指出,虽然缓存等概念并不新颖,但SourceFS的关键创新在于其通用的、与构建系统无关的缓存*任何*构建步骤的方法。 目前该产品采用“与我们联系”的定价模式,表明它更适合拥有复杂代码库和支持基础设施的大型组织。SourceFS团队计划在未来的博客文章中分享更多技术细节,重点介绍实现方式以及如何与不同的构建系统集成。一些评论员指出,类似的方法已经存在,但通常需要大量的内部开发和维护。
相关文章

原文

SourceFS - a high-performance virtual filesystem that builds Android 9× faster, cuts compute costs by 14×, and reduces disk usage by 83× — unlocking a new level of developer productivity.

Slow Builds and Code Checkouts

Today's connected devices are powered by some of the largest codebases ever developed.

The latest Linux kernel has 40 Million lines of code while the Android AOSP has 140M+, and this is just the foundation. Real-world device codebases are far larger – add the code for hardware support, custom features, services, additional OSs and a smartphone quickly tops 200M lines of code, while an Electric Vehicle exceeds 500M. And these codebases continue to grow throughout a device’s lifetime, with each software update.

Every code checkout pulls millions of files and hundreds of GB, every build runs hundreds of thousands of steps. And because dependency graphs at this scale are imperfect, even a small change can trigger a massive rebuild or, worse, produce an incorrect result. 

The impact: hours of developer time lost every day and $ millions wasted on ever increasing CI compute requirements — or more often, configurations that are not tested due to compute constraints.


The Source File System (SourceFS)

Not another build system. Meet SourceFS – a high-performance virtual file system that delivers unparalleled speedups when checking out and building the Android codebase. It integrates seamlessly into your existing developer workflows and CI, with near-zero migration overhead, and dramatically lowers compute costs. Here’s how it works.

At its core, SourceFS virtualizes everything, materializes on demand, and does all of this transparently — so neither you nor the rest of the system ever notice it.

SourceFS accelerates code checkouts by over 10×. It does this by creating a virtual file representation of the entire codebase at checkout and materializing files on demand, instantly, the moment you need them. These virtual files look and behave just like real ones, with the correct permissions, timestamps, and attributes, yet their content appears, as if by magic, only if required.

This eliminates the need to download hundreds of GB of untouched code, drastically reducing disk space requirements. And given that most changes only affect a small fraction of the codebase, most files remain virtual and are never materialized. All this is seamlessly integrated with Git and Repo.

SourceFS accelerates builds by up to 10×. Every build step, when first encountered, is executed in a lightweight sandbox that records all inputs, outputs, and environment. This covers over 99% of the build steps – not just compilation, but linking, packaging, generating docs, and more. As the build runs, any step that exactly matches a prior record is skipped and the results are automatically reused; any new or invalidated steps, for example from your local changes, are executed and recorded for future use.

Under the hood, SourceFS packs novel algorithms, advanced virtualization, high-performance caching and replay, efficient sandboxing, and a state-of-the-art backend with near-zero overhead, that is built to scale across your entire organization. Most of this is written in Rust and powered by decades of kernel and operating system advancements and expertise.

Fast Builds, Efficient Storage and Cost Savings

The results of checking out code and building in a SourceFS environment are truly impressive.

Fast checkouts, even when compared to the most optimised standard way of downloading the code, are over 20x faster. The SourceFS code checkout gives developers a working Git tree, and aside from running in a SourceFS backed folder, everything else is the same workflows developers are already used to. 

In addition to speed, a non-obvious superpower is the fact that with SourceFS a codebase takes a small amount of disk space. This is game-changing for device developers, who often need to switch between multiple codebases — one for each device type, and sometimes even for individual device versions.

Fixing large-scale bugs, that affect multiple device codebases, or even just checking out another codebase to see how something is implemented is seamless and similar to working on a small GitHub repository.

Fast builds are what truly makes a difference to developer productivity. With SourceFS builds complete over 9x faster on a regular developer machine. This sets a new standard as it enables developers to get their sword fighting time back and speeds-up the lengthy feedback loop on CI pipelines.

Even compared to other fast build solutions, SourceFS achieves significantly better performance, by being able to replay nearly all the build steps - across all programming languages, compilers and all the other tools used in a device codebase – think packaging, linking, documentation and a lot more. 

Cost savings are what makes a difference for organizations. The ability to achieve more with the same compute budget or to reduce the costs where they have grown out of control is what truly matters from a financial standpoint.

To understand the impact SourceFS has on costs, it helps to look at the priorities of fast-paced device organizations, where developers can’t wait for over two hours for a build to finish. In such teams, developers use the most powerful machines available to stay productive.

While powerful machines reduce build times to a more reasonable level, they still perform significantly slower than SourceFS running on a standard machine — and at a much higher cost. Here, SourceFS not only delivers better performance but also enables cost savings of up to 14×.

Alternatives: Why They Fall Short

SourceFS builds on prior efforts. Each approach listed below has its own place, yet in our experience they all fall short when faced with the complexity of a modern device codebase.

Migrating to a new build system (Bazel, Buck2)

SourceFS delivers the performance gains of modern build systems like Bazel or Buck2 – while also accelerating checkouts – all without requiring any migration.

Moving a device codebase to a new build system is a massive undertaking that even well-resourced teams have abandoned midway. Further still, this complexity multiplies for real device codebases, like electric vehicles, that incorporate multiple operating systems (Yocto, Android, QNX), each with its own bespoke build system.

Using a compiler wrapper (REClient, Goma)

An intermediate step, short of migrating to a new build system, is to use a compiler wrapper that enables caching and replay via a remote-execution protocol. However, wrappers cover only a subset of build actions, so they speed up only part of the build – and don’t help checkouts. They’re also brittle as they rely on parsing command-line flags and correctly inferring inputs/outputs, which can break in unexpected ways.

Next Steps

We are rapidly expanding SourceFS support to more real world device codebases, including support for other operating systems, like Yocto, in parallel with optimising performance even further.

Fast builds and checkouts are the first superpowers in our mission to transform how software for smart devices is developed and maintained – making it simpler, faster, and cost-effective. Stay tuned!  

联系我们 contact @ memedata.com