kbandla / dpkt

fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols
Other
1.09k stars 270 forks source link

Performance regression in v1.9.7 #611

Closed Hans-JakobHoltzTT closed 3 years ago

Hans-JakobHoltzTT commented 3 years ago

Deserializing an Ethernet frame carrying IPv4 and UDP takes considerably longer with 1.9.7, compared to 1.9.6:

from timeit import timeit
from dpkt.ethernet import Ethernet
from dpkt.ip import IP
from dpkt.udp import UDP

data = bytes(Ethernet(dst=bytes([0xff]*6),
               src=bytes([0]*6),
               data=IP(src=bytes([127,0,0,1]),
                       dst=bytes([255,255,255,255]),
                       data=UDP(sport=1234,
                                dport=5000,
                                data=b'foobar')
                             )
                     )
            )

timeit(lambda: Ethernet(data))

On my machine (i7-8750H, Windows 10, Python 3.7.4 64bit), 1.9.6 can do it in about 13 seconds whereas 1.9.7 takes about 19 seconds, i.e. more than 40% longer.

obormot commented 3 years ago

I will look into it

obormot commented 3 years ago

This is likely due to construction of __public_fields__ added to Packet.__init__. I will refactor this and submit a patch

obormot commented 3 years ago

PR https://github.com/kbandla/dpkt/pull/612 timing before the fix:

26.6 µs ± 1.82 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

after the fix:

17.4 µs ± 511 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
DerFetzer commented 3 years ago

Thank you very much for the fix! Performance in this case is back to the v1.9.6 baseline again.

I am a colleague of @Hans-JakobHoltzTT. You can close this issue.

obormot commented 3 years ago

@DerFetzer Thanks for confirming! We'll keep the issue open for visibility until we push a bugfix release (soon).

brifordwylie commented 3 years ago

@obormot let me know when you're ready and I'll push a new version to PyPI

obormot commented 3 years ago

@brifordwylie Latest master is ready to go.. it's just 1.9.7 + bugfix on top. Not sure what to do with the version though. Update existing 1.9.7 in github and push 1.9.7.2 to PyPI?

brifordwylie commented 3 years ago

@obormot 1.9.7.2 pushed to PyPI (https://github.com/kbandla/dpkt/pull/614)

obormot commented 3 years ago

@brifordwylie 🤗