Analysing the size of code-related entities

This page provides an analysis for the size of the image, with a focus on the size of code entities, like methods and classes.

For performance reasons the vaues of these metrics are caches in GtMemoryMetrics Object << #GtMemoryMetrics slots: { #cache }; package: 'GToolkit-Releaser' . They can be reset using the snippet below.

GtMemoryMetrics reset
  

Current image size is 670.88 MiB.

Total analysed size: 233.76 MiB

Methods: 64.55 MiB for 434933 methods.

The size of methods includes all bytecodes, additional state and literals. Literals include strings and literal arrays, but excludes symbols.

String literals size: 8.51 MiB

Classes: 95.38 MiB for 32091 classess.

Instance Side: 38.79 MiB

Without method dictionaries: 14.15 MiB

By componets: 38.46 MiB

Method dictionaries: 24.64 MiB

Basic Size in Memory: 3.26 MiB

Other: 10.56 MiB

Subclasses: 290.73 KiB

Protocols: 6.95 MiB

Layout: 751.82 KiB

Shared pools: 2.60 MiB

Class side: 56.59 MiB (metaclasses)

Without method dictionaries: 32.97 MiB

By componets: 29.28 MiB

Method dictionaries: 23.62 MiB

Basic Size in Memory: 1.96 MiB

Other: 3.70 MiB

Protocols: 2.97 MiB

Layout: 752.13 KiB

By data:

Basic Size in Memory: 5.21 MiB

Method dictionaries: 48.26 MiB

Subclasses: 290.73 KiB

Protocols: 9.91 MiB

Shared pools: 2.60 MiB

Layout: 1.47 MiB

The size of classes includes the size of the class object and various method dictionaries, but excludes the actual methods in those dictionaries

Symbols: 6.74 MiB for 217178 symbols

Pragmas Cache: 5.20 MiB

GT Completion Cache: 57.97 MiB

Packages: 1.84 MiB

Navigation Environment: 2.09 MiB

When using traits, metaclasses use two extra arrays. This can introduce a memory overhead when traits have many users.

Traits overhead: 12.75 MiB

This measures the size of several types of instances, to double check that the previous calculations did not miss something.

MethodDictionary Dictionary << #MethodDictionary layout: VariableLayout; slots: {}; tag: 'Methods'; package: 'Kernel-CodeModel' sanity check:

79620 instances

75.56 MiB using HashedCollection>>#gtSpecificSizeInMemory gtSpecificSizeInMemory ^ self sizeInMemory + array sizeInMemory

32.40 MiB using #selector instancesSizeInMemory "Answers the number of bytes consumed by all its instances including their object header. Note: we do not use #allInstances as allInstancesDo: has a fallback for low memory" | bytes | bytes := 0. self allInstancesDo: [:each | bytes := bytes + each sizeInMemory ]. ^ bytes

CompiledMethod CompiledCode << #CompiledMethod layout: CompiledMethodLayout; slots: {}; tag: 'Methods'; package: 'Kernel-CodeModel' :

435102 instances

64.58 MiB using CompiledMethod>>#gtSpecificSizeInMemory gtSpecificSizeInMemory ^ super gtSpecificSizeInMemory + (self penultimateLiteral isMethodProperties ifTrue: [ self penultimateLiteral sizeInMemory ] ifFalse: [ 0 ])

37.23 MiB using #selector instancesSizeInMemory "Answers the number of bytes consumed by all its instances including their object header. Note: we do not use #allInstances as allInstancesDo: has a fallback for low memory" | bytes | bytes := 0. self allInstancesDo: [:each | bytes := bytes + each sizeInMemory ]. ^ bytes

CompiledBlock CompiledCode << #CompiledBlock layout: CompiledMethodLayout; slots: {}; tag: 'Methods'; package: 'Kernel-CodeModel' instances

128698 instances

7.49 MiB using #selector instancesSizeInMemory "Answers the number of bytes consumed by all its instances including their object header. Note: we do not use #allInstances as allInstancesDo: has a fallback for low memory" | bytes | bytes := 0. self allInstancesDo: [:each | bytes := bytes + each sizeInMemory ]. ^ bytes