Automating dead code cleanup
Meta's SCARF framework finds dead code by building a cross-language, symbol-level dependency graph from Glean and augmenting it with runtime usage data such as API endpoint logs, URI dispatch tables and async job invocations, then garbage-collects unreachable nodes, subgraphs and cycles. Switching from per-symbol classifiers to whole-graph analysis raised dead code removal in one large codebase by nearly 50%, at the cost of a longer indexing and data-pipeline cycle that makes prototyping harder. Over five years SCARF has deleted more than 100 million lines in over 370,000 change requests generated through CodemodService, with some languages auto-merged without review. BigGrep textual-reference checks act as a conservative fallback, accepting false negatives to avoid unsafe deletions.
Related posts
- Automating product deprecation
Meta Engineering mediumAdeptSCARF (Systematic Code and Asset Removal Framework) is Meta's tooling for deprecating products by removing dead code and unused data, credited with deleting over 100M lines of code in five years and petabytes of data across 12.8M data types in 21 systems in one year. Engineers scope a deprecation by making only boundary decisions ("Flag Dependency" or "Add to Project"), and SCARF computes a daily-refreshed deletion roadmap that orders removals safely: mobile clients before GraphQL definitions, then business logic, schemas, and finally data. Static and dynamic usage signals block automated deletion of anything still in use. Engineers can triage or override those signals, for example deleting an endpoint that still gets trickle traffic, and generate targeted dependency-breaking code changes.
- Automating data removal
Meta Engineering mediumAdeptMeta's SCARF framework includes a subsystem that finds and deletes unused classes of data, such as tables, storage use cases and TAO object types, across 21 data systems. It combines static code references from Glean with runtime read counters instrumented into production data systems. When a type has no references and no traffic, SCARF files a ticket, blocks reads and writes as a dry run, and then deletes the data, with backups as a last safeguard. It models cross-system asset dependencies so deletions happen in the right order, and it will not break code references, relying on its dead-code subsystem to prune those first; in a year it removed petabytes across 12.8M data types.
- Protecting user data through source code analysis at scale
Meta Engineering mediumAdeptMeta's Anti-Scraping team encodes known scraping attack vectors as taint-analysis rules in its in-house static analyzers, Zoncolan for Hack and Pysa for Python, so potential vectors are flagged before code ships. Rules define sources (user-controlled parameters such as a result count or target ID) and sinks (data returned to the user), and a possible flow between them is raised as an issue for triage. In a mock followers endpoint, an uncapped count lets scrapers pull entire follower lists in one request and slip past rate limiting. The fix clamps count to a maximum, forcing scrapers into many more requests that rate limits then catch. Static analysis cannot catch scrapers that mimic legitimate usage, so it is one part of a broader defense.
- Fixit 2: Meta’s next-generation auto-fixing linter
Meta Engineering mediumAdeptFixit 2 is a partial rewrite of Meta's open-source Python auto-fixing linter, built on LibCST so rules can safely suggest and apply code replacements without regex or broken syntax. Compared with Flake8, which only reports line/column, cannot suggest fixes and relies on the stdlib ast module, Fixit 2 adds local in-repo lint rules, hierarchical TOML configuration for monorepos, and an improved CLI and API. A rule takes under a dozen lines with inline VALID/INVALID test cases, and passing a replacement CST node to report() supplies an autofix. Applied broadly, `fixit fix` can also drive codemods across a large codebase while the rule stays in place to catch new occurrences.
- An open source compositional deadlock detector for Android Java
Meta Engineering hardMasterMeta built a compositional static analyzer, now part of the open source Infer framework, that detects deadlocks in Android Java code without running it. Using abstract interpretation, it summarizes each method once in terms of "critical pairs": which lock it acquires while already holding a given set of locks, plus whether it runs on the main or a background thread. To scale to codebases with hundreds of millions of lines, it analyzes only the methods in a revision's modified files, then uses a heuristic to find outside methods that could deadlock with them. Deployed in CI on every commit to Meta's Android apps, it has led to over 200 fixes at about a 54% fix rate, and the analysis is proven sound and complete for an abstract language with non-deterministic control.