Attention is currently required from: pespin.
1 comment:
File src/target/trx_toolkit/data_msg.py:
Patch Set #2, Line 336: burst = memoryview(burst)[:EDGE_BURST_LEN]
I never used memoryview nor read about the details, but in line "burst = memoryview(burst)[:EDGE_BUR […]
ah, now I see. So memoryview(burst) creates only a view of original burst object data. This is basically a small object that points to another base object to know where to get the data without copying them. Then slice operation of memoryview returns another memoryview without copying the data - that adjusted memoryview refers to base object, but knows to view not the whole data of it, but only some range. It is still a small object that does not copy base's data.
```
In [7]: burst = bytearray(range(10))
In [8]: burst
Out[8]: bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t')
In [9]: burst *= 100
In [10]: burst
Out[10]: bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t...\x00\x01\x02\x03\x04\x05\x06\x07\x08\t')
In [11]: len(burst)
Out[11]: 1000
In [12]: sys.getsizeof(burst)
Out[12]: 1057
In [13]: m = memoryview(burst)
In [14]: len(m)
Out[14]: 1000
In [15]: sys.getsizeof(m)
Out[15]: 184
In [16]: m[0]
Out[16]: 0
In [17]: burst[0]
Out[17]: 0
In [18]: burst[1]
Out[18]: 1
In [19]: m[1]
Out[19]: 1
In [20]: m[2]
Out[20]: 2
In [21]: burst[2]
Out[21]: 2
In [22]: mm = m[2:]
In [23]: len(mm)
Out[23]: 998
In [24]: sys.getsizeof(mm)
Out[24]: 184
In [25]: mm[0]
Out[25]: 2
In [26]: m[2]
Out[26]: 2
In [27]: mm[1]
Out[27]: 3
In [28]: m[3]
Out[28]: 3
In [29]: burst[3]
Out[29]: 3
```
Please see https://docs.python.org/3/library/stdtypes.html#memoryview for details.
P.S. Unfortunately constant-size of memoryview structure turned out to be not so small, so it still contributes to overhead for not so small bursts. https://github.com/python/cpython/blob/v3.11.9-9-g1b0e63c81b5/Include/memoryobject.h#L57-L66
To view, visit change 39537. To unsubscribe, or for help writing mail filters, visit settings.