golang / tools
Unit Size

The distribution of size of units (measured in lines of code).

Intro
  • Unit size measurements show the distribution of size of units of code (methods, functions...).
  • Units are classified in four categories based on their size (lines of code): 1-20 (small units), 20-50 (medium size units), 51-100 (long units), 101+ (very long units).
  • You should aim at keeping units small (< 20 lines). Long units may become "bloaters", code that have increased to such gargantuan proportions that they are hard to work with.
Learn more...
Unit Size Overall
  • There are 6,247 units with 100,126 lines of code in units (74.8% of code).
    • 97 very long units (14,351 lines of code)
    • 307 long units (21,038 lines of code)
    • 961 medium size units (30,064 lines of code)
    • 1,249 small units (18,240 lines of code)
    • 3,633 very small units (16,433 lines of code)
14% | 21% | 30% | 18% | 16%
Legend:
101+
51-100
21-50
11-20
1-10
Unit Size per Extension
101+
51-100
21-50
11-20
1-10
go14% | 21% | 30% | 17% | 16%
ts0% | 24% | 35% | 25% | 15%
js0% | 6% | 18% | 36% | 38%
Unit Size per Logical Component
primary logical decomposition
101+
51-100
21-50
11-20
1-10
go18% | 21% | 27% | 16% | 16%
internal10% | 20% | 33% | 18% | 17%
cmd21% | 21% | 25% | 18% | 13%
refactor20% | 31% | 25% | 15% | 7%
godoc3% | 14% | 28% | 25% | 26%
present15% | 26% | 30% | 12% | 14%
gopls0% | 17% | 45% | 25% | 11%
blog0% | 61% | 21% | 13% | 3%
container0% | 14% | 48% | 14% | 22%
playground0% | 16% | 45% | 21% | 16%
cover0% | 35% | 42% | 8% | 13%
copyright0% | 0% | 82% | 17% | 0%
imports0% | 0% | 90% | 0% | 9%
benchmark0% | 0% | 32% | 68% | 0%
txtar0% | 0% | 0% | 59% | 40%
Alternative Visuals
Longest Units
Top 20 longest units
Unit# linesMcCabe index# params
func serverDispatch()
in internal/lsp/protocol/tsserver.go
503 145 4
func binop()
in go/ssa/interp/ops.go
444 212 4
func setup()
in cmd/goyacc/yacc.go
289 73 0
func NewFile()
in cmd/splitdwarf/internal/macho/file.go
264 49 1
func extractFunctionMethod()
in internal/lsp/source/extract.go
256 66 7
func run()
in go/analysis/passes/asmdecl/asmdecl.go
239 83 1
func()
in internal/lsp/source/options.go
214 74 1
func()
in go/ssa/builder.go
209 50 1
func childrenOf()
in go/ast/astutil/enclosing.go
201 69 1
func main()
in cmd/splitdwarf/splitdwarf.go
196 29 0
func()
in internal/lsp/source/completion/format.go
195 54 1
func()
in go/packages/golist.go
193 55 1
func visitInstr()
in go/ssa/interp/interp.go
191 60 2
func()
in go/ast/astutil/rewrite.go
189 65 1
func()
in refactor/satisfy/find.go
183 65 1
func()
in go/packages/golist_overlay.go
180 54 1
func conv()
in go/ssa/interp/ops.go
175 72 3
func parseSections()
in present/parse.go
172 58 5
func run()
in go/analysis/unitchecker/unitchecker.go
170 27 3
func fiximports()
in cmd/fiximports/main.go
169 46 1