Repository navigation
perf(const): import the const enum packages lazily (#2729) - #2735
Merged
Merged
Conversation
Every pcapkit.const package imported all of its enumeration modules with itself, and pcapkit.const star-imported every package, so touching one enumeration loaded them all. Only the TCP and UDP app-type registries loaded on first use (#1538). - utilities.lazy: lazy_exports builds a package's PEP 562 __getattr__ and __dir__ from an exports table, or from the __all__ of subpackages it re-exports; it generalises the #1538 hooks. - const: each package names its exports under TYPE_CHECKING and binds the hooks, and pcapkit.const re-exports its subpackages through them, so importing it loads no enumeration module. - const.reg.apptype: SCTP and DCCP load on first use as TCP and UDP do. _Registries is an immutable Info keyed by TransportProtocol rather than a dict subclass (#2726); AppType.__registries__ is typed as a Mapping, in the crawler template too. - tests: conftest warms every const module; the #1538 tests cover SCTP, DCCP, the Info registries and a bare import of pcapkit.const; new sweeps hold every const package's __all__, dir() and member pickles to the eager behaviour; the #2656 test reads the lazy_exports call. - docs: a page for pcapkit.utilities.lazy, and the ruling on const-vendor-pairing. The new and changed laziness tests fail on 468f9c2 without the pcapkit/ change; the const, vendor, utilities, corekit, protocols root and schema, and project modules pass, as do the const and utilities unittest legs.
Owner
Author
|
GOOD TO GO at
|
Contributor
|
Coverage: 94.44% (unit tier, Python 3.15,
Per-file detail: the |
JarryShaw
added a commit
that referenced
this pull request
Nov 3, 2026
- Breaking: a short CALIPSO, SMF_DPD or MPL Opt Data Len raises ProtocolError, where 1.5.x raised FieldValueError, and a cut after the type octet reads short (#2737), a new entry; AppType.__registries__ is an Info, into the #2734 entry (#2735). - Changed: const packages import their enumerations lazily through pcapkit.utilities.lazy.lazy_exports (#2735); the docs extra pins sphinx-autodoc-typehints 3.17.4 (#2742), as 1.5.0 recorded its pin. - Fixed: the dumps keep a field renamed for clashing with an Info builtin name (#2736). - Folded: the GraalPy leg's timeout and shards into the CI-legs entry (#2741); the #2735 and #2737 rulings into the conventions entry. - No entry for the docs-only #2744 and #2746. - 1.6.0's :func:`bytes` role is :class:`bytes`, so the changelog pages build with no nitpicky warning. Old values measured against v1.5.1. - CHANGELOG.md regenerated; util/changelog_md.py --check passes.
1 of 5 tasks
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 behaviourThis applies the owner's rulings: the
pcapkit.constenum packages import lazily, the AppType registry loads SCTP and DCCP lazily the way it already loads TCP and UDP, and_Registriesstops being adictsubclass (#2726).pcapkit.utilities.lazy.lazy_exportsis one shared helper. It gives a package a__getattr__and__dir__built from its export table. Everyconstpackage uses it.from pcapkit.const.x import Y, attribute access,dir(),__all__, star-imports, theAttributeErrormessages and member pickles all matchmain, and a cross-tree fingerprint shows no difference._Registriesis an@info_finalInfo. It stays lazy and becomes immutable. It is undocumented, and nothing inpcapkitmutated it.Measured, plainly.
import pcapkitis not measurably faster: 686 ms onmainagainst 679 ms here, the median of 9 fresh processes. The protocol modules import most const modules at module level, so the saving waits on #2730.import pcapkit.conston its own, with the parent package stubbed out, drops from 189 ms to 52 ms. Treat this as groundwork for #2730 rather than a speed-up on its own.Closes #2729