Sloc Cloc and Code (commonly known as scc) is an ultra-fast, open-source command-line tool written in pure Go designed to count lines of code, blank lines, and comment lines across hundreds of programming languages. Developed by Ben Boyter, it acts as a modern, high-performance alternative to traditional tools like cloc.
Beyond just counting physical lines, scc provides advanced metrics like code complexity estimations, duplicate file detection, and project cost tracking. Key Tips and Architectural Tricks
The extreme performance of scc relies on unique optimization tricks that allowed it to outperform traditional counters and even highly optimized Rust implementations under various workloads.
Concurrency Scaling: It utilizes Go’s native concurrency. The tool runs faster the more CPU cores you feed into it.
Lazy Loading Language Specs: Earlier versions checked definitions for all 220+ languages on every file. The author optimized this by lazy loading language rules only when a file matching that language is encountered, drastically slashing CPU burn.
Avoiding Heavy OS Overhead: In many code counters, walking the file tree is the primary bottleneck. scc avoids the slow default file walkers that issue os.Stat on every node sequentially, moving instead to a custom, parallelized tree walk.
State Jump Optimization: When scc matches a multi-line comment or string format, it caches the offset to skip scanning those internal bytes entirely, avoiding repetitive string lookups. Evolving Trends in Code Counting
How developers use tools like scc has evolved from looking at sheer volume to extracting smart codebase health trends: YouTube·GopherConAU GopherConAU 2019 – Ben Boyter – Sloc Cloc and Code
Leave a Reply