Skip to content
Success

Changes

Summary

  1. trx_toolkit/burst_fwd: Use 'is' instead of '==' when checking if trx is (details)
  2. trx_toolkit/*: Don't use `del x; x = None` idiom (details)
  3. trx_toolkit/udp_link: Factor code to describe remote into .desc_remote() (details)
Commit bc80c197cd73126ab37d42463e467bda9d7dc42c by Vadim Yanitskiy
trx_toolkit/burst_fwd: Use 'is' instead of '==' when checking if trx is src_trx

In python `a is b` is just a pointer comparison of locations of objects
a and b, while `a == b` can involve doing arbitrary code invoking __eq__
and is generally slower even without __eq__ defined:

    In [1]: class A:
       ...:     pass
       ...:

    In [2]: a = A()
    In [4]: b = A()

    In [5]: a == a
    Out[5]: True

    In [6]: a == b
    Out[6]: False

    In [7]: a is a
    Out[7]: True

    In [8]: a is b
    Out[8]: False

    In [9]: %timeit a is a
    84.2 ns ± 0.133 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

    In [10]: %timeit a is b
    87.5 ns ± 0.0736 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

    In [11]: %timeit a == a
    100 ns ± 0.659 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

    In [12]: %timeit a == b
    116 ns ± 0.399 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

BurstForwarder.forward_msg is one of the hottest places, as e.g. for every
received packet from BTS it forwards it to multiple Ms receivers. It
makes sense to be careful and save cycles here.

Change-Id: Ic9e16720daeb348b5f9c535c24a682db53a93529
The file was modifiedsrc/target/trx_toolkit/burst_fwd.py
Commit 5c593892596d896ac9f1129548ccefc6b26670e3 by Vadim Yanitskiy
trx_toolkit/*: Don't use `del x; x = None` idiom

In Python it is enough to do `x = None` to release the object that was
pointed to by x previously. So at Python level doing this extra
del only spends more CPU time, but when we will switch to Cython, and
e.g. Msg.burst will be a C-level attribute, the following will not work
at all

del msg.burst
msg.burst = None

because at runtime it will complain that

        del msg.burst
    AttributeError: 'Msg' object has no attribute 'burst' and no __dict__ for setting new attributes

-> Remove unneeded del to save some time and avoid problems with upcoming switch to Cython.

Change-Id: I7a83bdd52fb9318bd8b975f85ce37c7144873f61
The file was modifiedsrc/target/trx_toolkit/clck_gen.py
The file was modifiedsrc/target/trx_toolkit/fake_trx.py
The file was modifiedsrc/target/trx_toolkit/burst_fwd.py
Commit 02d0614de8e0b425fbcead6fbb33be04a5f2a59f by Vadim Yanitskiy
trx_toolkit/udp_link: Factor code to describe remote into .desc_remote() function

And use that utility everywhere where remote of UDPLink is logged.

The reason we are doing this is that with upcoming switch to Cython the
way remote address is stored will change to `struct sockaddr_in` and
instead of updating all users, we will need to only change
UDPLink.desc_remote() in one place.

Add .desc_local() for symmetry.

Change-Id: I1e2fa560ada7a8de4c9b9150058c2a1c73874fbe
The file was modifiedsrc/target/trx_toolkit/data_if.py
The file was modifiedsrc/target/trx_toolkit/udp_link.py