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

Total analysed size: 223.72 MiB

Methods: 61.70 MiB for 424737 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.60 MiB

Classes: 91.13 MiB for 31055 classess.

Instance Side: 37.01 MiB

Without method dictionaries: 13.09 MiB

By componets: 36.61 MiB

Method dictionaries: 23.92 MiB

Basic Size in Memory: 3.15 MiB

Other: 9.54 MiB

Subclasses: 281.80 KiB

Protocols: 6.06 MiB

Layout: 727.54 KiB

Shared pools: 2.50 MiB

Class side: 54.12 MiB (metaclasses)

Without method dictionaries: 31.37 MiB

By componets: 27.96 MiB

Method dictionaries: 22.75 MiB

Basic Size in Memory: 1.89 MiB

Other: 3.32 MiB

Protocols: 2.61 MiB

Layout: 727.85 KiB

By data:

Basic Size in Memory: 5.04 MiB

Method dictionaries: 46.67 MiB

Subclasses: 281.80 KiB

Protocols: 8.67 MiB

Shared pools: 2.50 MiB

Layout: 1.42 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.44 MiB for 210042 symbols

Pragmas Cache: 5.00 MiB

GT Completion Cache: 55.58 MiB

Packages: 1.82 MiB

Navigation Environment: 2.04 MiB

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

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

76884 instances

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

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

424899 instances

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

35.99 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

122563 instances

7.17 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