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

Total analysed size: 237.30 MiB

Methods: 65.75 MiB for 440278 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.70 MiB

Classes: 96.46 MiB for 32436 classess.

Instance Side: 39.33 MiB

Without method dictionaries: 14.33 MiB

By componets: 39.00 MiB

Method dictionaries: 25.00 MiB

Basic Size in Memory: 3.29 MiB

Other: 10.71 MiB

Subclasses: 293.79 KiB

Protocols: 7.04 MiB

Layout: 759.91 KiB

Shared pools: 2.64 MiB

Class side: 57.13 MiB (metaclasses)

Without method dictionaries: 33.25 MiB

By componets: 29.59 MiB

Method dictionaries: 23.89 MiB

Basic Size in Memory: 1.98 MiB

Other: 3.72 MiB

Protocols: 2.98 MiB

Layout: 760.22 KiB

By data:

Basic Size in Memory: 5.27 MiB

Method dictionaries: 48.88 MiB

Subclasses: 293.79 KiB

Protocols: 10.02 MiB

Shared pools: 2.64 MiB

Layout: 1.48 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.85 MiB for 220397 symbols

Pragmas Cache: 5.27 MiB

GT Completion Cache: 59.02 MiB

Packages: 1.85 MiB

Navigation Environment: 2.11 MiB

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

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

80418 instances

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

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

440446 instances

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

37.84 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

132887 instances

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