Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix: bound duplicate-packet dedup against alternating-payload floods #1743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
fix: bound duplicate-packet dedup against alternating-payload floods #1743
Changes from all commits
9569654e3cfde85d9864bf1079b22b1d2616fe028c1b035fd3b921184eceea56bcbe4c5c521310c7fc30File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is hot, you need to cythonize with -A and look at the html to see how bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do — running
REQUIRE_CYTHON=1 poetry install --only=main,devthencython -a src/zeroconf/_listener.pyand inspecting the generated.htmlfor yellow lines on the hot path (the dedup check at the top of_process_datagram_at_timeand the move-to-end block at the bottom). Will also look at whetherrecent = recent_packets.get(data)withcython.locals(recent=cython.tuple)produces a clean typed access forrecent[0]/recent[1], or whether we need an explicitcdef tuple recentdeclaration in the.pxdto skip the generic-object indexing path.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding to this — three specific spots to verify on the generated
.htmlare worth more than the rest:The dedup check at L113-118.
recent_packets.get(data)should compile to a directPyDict_GetItem(the cdef'd_recent_packetsshould make the attribute access C-typed). Therecent[0]/recent[1]indexing depends on whetherrecent=cython.tuplein@cython.localsis enough to getPyTuple_GET_ITEM— if not, you'll see yellow indexing through the generic object protocol and may need an explicitcdef tuple recentin the .pxd locals.The freshness compare.
(now - _DUPLICATE_PACKET_SUPPRESSION_INTERVAL) < recent[0]— with the cdef on_DUPLICATE_PACKET_SUPPRESSION_INTERVALremoved from the .pxd, this now goes throughPyLong_AsLongon every packet. Either re-cdef via thepublic + cdef aliaspattern (so tests can still patch it) or accept the regression and capture the CodSpeed delta in the PR body so reviewers know the trade-off was deliberate.The eviction line.
del recent_packets[next(iter(recent_packets))]allocates an iter each call when the window is full — worth checking if Cython can flatten that, or if it stays yellow. If yellow and CodSpeed regresses, apopitemon an OrderedDict or caching the head externally are options.If any of those come out deep yellow on the hot path, paste the relevant block into the PR for a second look before landing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CodSpeed delta on the PR report (+57.04% improvement) is a strong signal that the dict-based approach beats the single-slot version net-net even with the move-to-end mutations on hit. But the
cython -aaudit is still worth getting on record before merge — three specific lines worth a close look in the generated.html:recent = recent_packets.get(data)— should be a directPyDict_GetItemgivenself._recent_packetsis cdef'd ascython.dict. Confirm no yellow.recent[0]/recent[1]in the dedup check — these depend on whether the@cython.locals(recent=cython.tuple)in the.pxdis sufficient to getPyTuple_GET_ITEM. If they show yellow, an explicitcdef tuple recentline in the.pxdwill fix it.(now - _DUPLICATE_PACKET_SUPPRESSION_INTERVAL) < recent[0]— with the cdef'dunsigned inton the constant anddoubleonnow, this should compile to a clean C compare; verify noPyNumber_Subtractslow path.For the move-to-end on hit (
del recent_packets[data]; recent_packets[data] = recent), this is the per-duplicate hot line; verify both mutations stay on thePyDict_*C path. Worth pasting a screenshot of the relevant lines into the PR thread for future reference, since this is now load-bearing performance code.Uh oh!
There was an error while loading. Please reload this page.