apple / swift
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 44,045 units with 520,848 lines of code in units (45.4% of code).
    • 444 very long units (84,909 lines of code)
    • 1,182 long units (80,801 lines of code)
    • 4,209 medium size units (131,563 lines of code)
    • 6,274 small units (91,099 lines of code)
    • 31,936 very small units (132,476 lines of code)
16% | 15% | 25% | 17% | 25%
Legend:
101+
51-100
21-50
11-20
1-10
Unit Size per Extension
101+
51-100
21-50
11-20
1-10
cpp19% | 18% | 27% | 17% | 17%
h4% | 4% | 9% | 13% | 67%
swift5% | 6% | 23% | 26% | 37%
py14% | 10% | 27% | 17% | 29%
m74% | 0% | 5% | 13% | 7%
c19% | 30% | 11% | 15% | 22%
inc0% | 37% | 13% | 20% | 29%
mm0% | 16% | 15% | 29% | 38%
Unit Size per Logical Component
primary logical decomposition
101+
51-100
21-50
11-20
1-10
lib18% | 18% | 27% | 17% | 18%
tools21% | 17% | 24% | 15% | 20%
include6% | 3% | 8% | 13% | 68%
utils16% | 11% | 28% | 17% | 26%
stdlib6% | 12% | 29% | 18% | 32%
validation-test5% | 3% | 12% | 34% | 45%
benchmark4% | 0% | 17% | 22% | 54%
unittests0% | 5% | 20% | 28% | 45%
SwiftCompilerSources0% | 8% | 30% | 21% | 39%
Alternative Visuals
Longest Units
Top 20 longest units
Unit# linesMcCabe index# params
bool SILParser::parseSpecificSILInstruction()
in lib/SIL/Parser/ParseSIL.cpp
2765 955 5
NodePointer NodePrinter::print()
in lib/Demangling/NodePrinter.cpp
1741 493 3
bool SILDeserializer::readSILInstruction()
in lib/Serialization/DeserializeSIL.cpp
1653 259 4
void SILSerializer::writeSILInstruction()
in lib/Serialization/SerializeSIL.cpp
1460 274 1
void irgen::emitBuiltinCall()
in lib/IRGen/GenBuiltin.cpp
930 165 6
static void diagSyntacticUseRestrictions()
in lib/Sema/MiscDiagnostics.cpp
928 246 3
bool ConstraintSystem::repairFailures()
in lib/Sema/CSSimplify.cpp
869 292 5
bool Parser::parseNewDeclAttribute()
in lib/Parse/ParseDecl.cpp
813 186 4
def create_argument_parser()
in utils/build_swift/build_swift/driver_arguments.py
790 38 0
TypeLookupErrorOr decodeMangledType()
in include/swift/Demangling/TypeDecoder.h
658 203 3
Type Type::transformRec()
in lib/AST/Type.cpp
620 188 1
static int handleTestInvocation()
in tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp
615 134 2
void SILGenFunction::emitDistributedThunk()
in lib/SILGen/SILGenDistributed.cpp
572 61 1
ImportedName NameImporter::importNameImpl()
in lib/ClangImporter/ImportName.cpp
563 184 3
void TestSwiftObjectNSObject()
in validation-test/stdlib/Inputs/SwiftObjectNSObject/SwiftObjectNSObject.m
557 10 2
void handleRequestImpl()
in tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp
484 101 3
int main()
in tools/swift-ide-test/swift-ide-test.cpp
462 107 2
RuntimeEffect swift::getRuntimeEffect()
in lib/SIL/Utils/InstructionUtils.cpp
441 259 2
432 100 1
llvm::Error DeclDeserializer::deserializeDeclCommon()
in lib/Serialization/Deserialization.cpp
417 67 0