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

Total analysed size: 212.87 MiB

Methods: 58.39 MiB for 411896 methods.

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

Classes: 86.36 MiB for 29934 classess.

Instance Side: 34.90 MiB

Class side: 51.46 MiB (metaclasses)

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.25 MiB for 204549 symbols

Pragmas Cache: 4.85 MiB

GT Completion Cache: 53.27 MiB

Packages: 1.77 MiB

Navigation Environment: 1.99 MiB

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

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

74228 instances

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

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

412060 instances

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

34.77 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

ClassOrganization Object << #ClassOrganization slots: {}; package: 'GToolkit-Pharo11Stubs' :

0 instances

0 B using ClassOrganization>>#gtSpecificSizeInMemory gtSpecificSizeInMemory ^ self sizeInMemory + protocolOrganizer gtSpecificSizeInMemory