Attention is currently required from: pespin.

kirr has posted comments on this change by kirr. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/39537?usp=email )

Change subject: trx_toolkit/*: Try to avoid copying burst data where possible
......................................................................


Patch Set 2:

(1 comment)

File src/target/trx_toolkit/data_msg.py:

https://gerrit.osmocom.org/c/osmocom-bb/+/39537/comment/7ef9a2d0_e46bcac8?usp=email
 :
PS2, 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 https://gerrit.osmocom.org/c/osmocom-bb/+/39537?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I147da2f110dedc863361059c931f609c28a69e9c
Gerrit-Change-Number: 39537
Gerrit-PatchSet: 2
Gerrit-Owner: kirr <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-CC: fixeria <[email protected]>
Gerrit-CC: osmith <[email protected]>
Gerrit-Attention: pespin <[email protected]>
Gerrit-Comment-Date: Thu, 13 Feb 2025 20:22:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: kirr <[email protected]>
Comment-In-Reply-To: pespin <[email protected]>

Reply via email to