openai / codex
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...
  • To learn more about unit size, the Sokrates recommends the following resources:
    • Function Length, MartinFowler.com
      • "If you have to spend effort into looking at a fragment of code to figure out what it's doing, then you should extract it into a function and name the function after that 'what'."
    • Stack Overflow Discussion on Unit Size, stackoverflow.com
      • "Use common sense, stick to small function sizes in most instances but don't be dogmatic about it if you have a genuinely good reason to make an unusually big function."
    • Coding Smells, codinghorror.com
      • "All other things being equal, a shorter method is easier to read, easier to understand, and easier to troubleshoot. Refactor long methods into smaller methods if you can."
    • Clean Code: A Handbook of Agile Software Craftsmanship, by Robert Martin
      • "The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that. Functions should not be 100 lines long. Functions should hardly ever be 20 lines long."
Unit Size Overall
  • There are 15,934 units with 264,985 lines of code in units (35.2% of code).
    • 139 very long units (21,865 lines of code)
    • 606 long units (40,249 lines of code)
    • 3,176 medium size units (96,928 lines of code)
    • 4,084 small units (60,781 lines of code)
    • 7,929 very small units (45,162 lines of code)
8% | 15% | 36% | 22% | 17%
Legend:
101+
51-100
21-50
11-20
1-10
Unit Size per Extension
101+
51-100
21-50
11-20
1-10
rs7% | 15% | 37% | 22% | 16%
py15% | 10% | 24% | 21% | 27%
ts0% | 22% | 28% | 26% | 21%
js0% | 0% | 0% | 100% | 0%
Unit Size per Logical Component
primary logical decomposition
101+
51-100
21-50
11-20
1-10
TUI frontend8% | 14% | 38% | 23% | 15%
app-server API11% | 21% | 37% | 18% | 10%
core engine6% | 15% | 36% | 21% | 20%
extensibility (MCP, plugins, skills, hooks)7% | 14% | 39% | 25% | 12%
sandboxing & policy7% | 14% | 38% | 22% | 17%
configuration14% | 14% | 36% | 20% | 14%
repo tooling & CI17% | 12% | 25% | 19% | 26%
CLI & headless frontends6% | 18% | 34% | 22% | 17%
extensions (ext/*)12% | 13% | 36% | 18% | 17%
shared infrastructure (utils & leaf crates)8% | 10% | 35% | 25% | 20%
exec-server (sandboxed executor)9% | 5% | 29% | 27% | 27%
persistence (rollout, state, thread-store)5% | 15% | 34% | 22% | 22%
protocol (shared vocabulary)3% | 22% | 39% | 20% | 13%
code-mode (V8 runtime)6% | 15% | 35% | 18% | 23%
model backends & API clients0% | 8% | 32% | 36% | 22%
sdk (TypeScript & Python)0% | 11% | 23% | 30% | 33%
auth & identity0% | 12% | 32% | 30% | 24%
by-layer logical decomposition
101+
51-100
21-50
11-20
1-10
frontends8% | 15% | 37% | 23% | 15%
API server & extensions11% | 18% | 38% | 20% | 12%
services (config, persistence, sandbox, exec-server, models, auth)6% | 13% | 35% | 25% | 19%
engine6% | 15% | 35% | 21% | 20%
vocabulary & utilities5% | 15% | 37% | 23% | 17%
Alternative Visuals
Longest Units
Top 50 longest units
Unit# linesMcCabe index# params
447 1 0
444 69 1
411 1 0
387 22 1
332 1 1
331 25 1
327 50 4
324 2 2
321 22 5
316 28 0
294 39 3
292 1 0
282 1 0
257 34 1
250 29 2
247 19 7
238 49 2
235 29 3
219 50 0
218 9 3
216 30 1
213 21 3
212 27 4
194 41 2
193 25 2
191 19 6
190 31 0
188 1 0
187 1 1
185 12 3
183 9 0
177 2 2
174 1 0
173 4 0
170 22 6
170 9 3
162 17 4
159 20 3
159 14 3
154 24 2
153 21 3
150 30 3
149 8 2
148 8 2
147 1 2
147 54 2
147 13 5
147 37 1
147 21 0
146 12 5