You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we store tuple elements inside Swift array (elements: [PyObject]). The better idea would be to allocate more space after the tuple and store elements there (this is called flexible array member in C). This saves a pointer indirection and is better for cache, since we can fit a few first elements in the same line as type, __dict__ etc. We can also do this for other immutable container types:
str - currently native Swift String. This would force us to implement our own String type - not hard, but takes a lot of time.
int - currently our own BigInt implementation (which does store values in Int32 range inside the pointer).
Calculating layout
This is not a problem since GenericLayout.Field already supports repeatCount:
internalstructGenericLayout{internalstructField{internalletsize:Intinternalletalignment:IntinternalletrepeatCount:Int
/// `repeatCount` is the number of times `type` is repeated:
/// ```c
/// struct DisnepPrincess {
/// char name[20];
/// };
/// sizeof (struct DisnepPrincess) // 20
/// ```
internalinit<T>(_ type:T.Type, repeatCount:Int=1){assert(repeatCount >=0)self.size = MemoryLayout<T>.size
self.alignment = MemoryLayout<T>.alignment
self.repeatCount = repeatCount
}}internalinit(initialOffset:Int, initialAlignment:Int, fields:[Field]){ things…}}
So, for tuple with count 5 we would have following layout:
PyObject things
PyTuple things - for example count and cached hash (though we have to remember that while tuple is immutable, the elements inside are not)
GenericLayout.filed(PyObject.self, repeatCount: 5) <- this is the new thing
Homo/hetero
Homomorphic - all allocated elements are layout compatible, both inline (for example RawPtr for storing multiple PyObjects) and on the heap (all PyObjects have the same header). This is true for tuple.
Heteromorphic - tail allocated elements can be different. Example for PyFrame.FastLocalsCellFreeBlockStackStorage :
fastLocals - PyObject?
cell/free - PyCell
blocks - PyFrame. Block - totally incompatible with PyObject? and PyCell
The text was updated successfully, but these errors were encountered:
Currently we store tuple elements inside Swift array (elements:
[PyObject]
). The better idea would be to allocate more space after the tuple and store elements there (this is called flexible array member in C). This saves a pointer indirection and is better for cache, since we can fit a few first elements in the same line astype
,__dict__
etc. We can also do this for other immutable container types:str
- currently native SwiftString
. This would force us to implement our ownString
type - not hard, but takes a lot of time.int
- currently our ownBigInt
implementation (which does store values inInt32
range inside the pointer).Calculating layout
This is not a problem since GenericLayout.Field already supports
repeatCount
:So, for tuple with count 5 we would have following layout:
PyObject
thingsPyTuple
things - for example count and cached hash (though we have to remember that whiletuple
is immutable, the elements inside are not)GenericLayout.filed(PyObject.self, repeatCount: 5)
<- this is the new thingHomo/hetero
RawPtr
for storing multiplePyObjects
) and on the heap (allPyObjects
have the same header). This is true fortuple
.PyFrame.FastLocalsCellFreeBlockStackStorage
:PyObject?
PyCell
PyFrame. Block
- totally incompatible withPyObject?
andPyCell
The text was updated successfully, but these errors were encountered: