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 645.88 MiB.

Total analysed size: 227.84 MiB

Methods: 62.71 MiB for 431579 methods.

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

String literals size: 7.69 MiB

Classes: 93.07 MiB for 31537 classess.

Instance Side: 37.70 MiB

Without method dictionaries: 13.32 MiB

By componets: 37.30 MiB

Method dictionaries: 24.38 MiB

Basic Size in Memory: 3.20 MiB

Other: 9.72 MiB

Subclasses: 286.13 KiB

Protocols: 6.16 MiB

Layout: 738.84 KiB

Shared pools: 2.55 MiB

Class side: 55.37 MiB (metaclasses)

Without method dictionaries: 32.13 MiB

By componets: 28.52 MiB

Method dictionaries: 23.25 MiB

Basic Size in Memory: 1.92 MiB

Other: 3.35 MiB

Protocols: 2.63 MiB

Layout: 739.15 KiB

By data:

Basic Size in Memory: 5.12 MiB

Method dictionaries: 47.63 MiB

Subclasses: 286.13 KiB

Protocols: 8.80 MiB

Shared pools: 2.55 MiB

Layout: 1.44 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.56 MiB for 213278 symbols

Pragmas Cache: 5.06 MiB

GT Completion Cache: 56.54 MiB

Packages: 1.84 MiB

Navigation Environment: 2.06 MiB

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

Traits overhead: 12.67 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:

78172 instances

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

31.87 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' :

431740 instances

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

36.59 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

124455 instances

7.25 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