Repository navigation
perf(protocols): import the packages above a protocol's on first use (#2730) - #2757
Merged
Merged
Conversation
…2730) * pcapkit.protocols, its layer packages and misc.pcap/misc.checksum name each protocol class under TYPE_CHECKING and resolve it through lazy_exports; pcapkit re-exports pcapkit.protocols the same way. A protocol's own package keeps its literal imports (#2753 layout). * pcapkit.protocols.__proto__ moves to the new pcapkit.protocols.registry module, built the first time it is reached; the foundation registry, reassembly and traceflow modules read it at call time instead of import. * protocol.py stays imported first from pcapkit.protocols, since defining Protocol imports Raw and NoPayload, which import it back. * tests: a sweep and cold-import checks of the lazy packages, the name registry, next-layer dispatch, selectors, pickling and the Shim6 entry ipv6_ext registers on import; conftest warms every protocol module; subclass walks reach every protocol first; the registry tests read pcapkit.protocols.__proto__; the apptype test expects SCTP's unloaded. * docs: the ruling on protocol-family-grouping, and the registry module. import pcapkit: median 640 ms -> 568 ms; protocol modules loaded 232 -> 129.
Owner
Author
|
GOOD TO GO at
|
Contributor
|
Coverage: 94.44% (unit tier, Python 3.15,
Per-file detail: the |
1 of 5 tasks
JarryShaw
added a commit
that referenced
this pull request
Nov 4, 2026
- Folded into the lazy-import entry (#2757): pcapkit.protocols, its layer packages, misc.pcap, misc.checksum and pcapkit import their protocol classes on first use, pcapkit.protocols.registry builds __proto__ on first read, and dir(pcapkit) lists none of the incidental names 1.5.1 listed (os, sys, ROOT, warnings, tbtrim), measured on a v1.5.1 export; the ruling into the conventions entry. - No mention of foundation.registry.protocols.protocol_registry, an import alias 1.5.1 neither exported nor documented, nor of an import time. - CHANGELOG.md regenerated; util/changelog_md.py --check passes.
This was referenced Nov 4, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
perf— changes performance, not behaviourDescription of your pull request and other information
pcapkit/protocols, each layer package,misc/pcap,misc/checksumandpcapkit/__init__now import their exports on first use, through the sharedlazy_exports. Each protocol package__init__keeps its literal imports, as ruled on #2753.import pcapkitmedian: 640 → 568 ms. Protocol modules loaded at import: 232 → 129. The remaining cost is mostlyfoundation.registry's wrapper modules importing their classes at module level; that can be a follow-up.pcapkit.protocols.registrybuilds__proto__in full on first read, andfoundationreads it at call time. So name-clash warnings, protochain lookups ('S_Tag' ina C-Tag frame) and next-layer dispatch behave as before. A cold-process test guards the Shim6 entry thatipv6_extadds on import.os,sys,ROOT, …) and the stray loop variablenameno longer appear indir(pcapkit). The private aliasfoundation.registry.protocols.protocol_registryis gone; readpcapkit.protocols.__proto__instead.Closes #2730