feat: speed up outgoing packet writer (#1313) · python-zeroconf/python-zeroconf@55cf4cc
@@ -15,8 +15,11 @@ cdef cython.uint _FLAGS_TC
1515cdef cython.uint _MAX_MSG_ABSOLUTE
1616cdef cython.uint _MAX_MSG_TYPICAL
171718+1819cdef bint TYPE_CHECKING
192021+cdef unsigned int SHORT_CACHE_MAX
22+2023cdef object PACK_BYTE
2124cdef object PACK_SHORT
2225cdef object PACK_LONG
@@ -28,6 +31,7 @@ cdef object LOGGING_IS_ENABLED_FOR
2831cdef object LOGGING_DEBUG
29323033cdef cython.tuple BYTE_TABLE
34+cdef cython.tuple SHORT_LOOKUP
31353236cdef class DNSOutgoing:
3337@@ -46,13 +50,15 @@ cdef class DNSOutgoing:
4650 cdef public cython.list authorities
4751 cdef public cython.list additionals
485249-cdef _reset_for_next_packet(self)
53+cpdef _reset_for_next_packet(self)
505451- cdef _write_byte(self, object value)
55+ cdef _write_byte(self, cython.uint value)
525653- cdef _insert_short_at_start(self, object value)
57+ cdef void _insert_short_at_start(self, unsigned int value)
545855- cdef _replace_short(self, object index, object value)
59+ cdef _replace_short(self, cython.uint index, cython.uint value)
60+61+ cdef _get_short(self, cython.uint value)
56625763 cdef _write_int(self, object value)
5864@@ -61,24 +67,29 @@ cdef class DNSOutgoing:
6167@cython.locals(
6268d=cython.bytes,
6369data_view=cython.list,
70+index=cython.uint,
6471length=cython.uint
6572 )
6673 cdef cython.bint _write_record(self, DNSRecord record, object now)
677475+@cython.locals(class_=cython.uint)
6876 cdef _write_record_class(self, DNSEntry record)
69777078@cython.locals(
7179start_size_int=object
7280 )
7381 cdef cython.bint _check_data_limit_or_rollback(self, cython.uint start_data_length, cython.uint start_size)
748275- cdef _write_questions_from_offset(self, object questions_offset)
83+@cython.locals(questions_written=cython.uint)
84+ cdef cython.uint _write_questions_from_offset(self, unsigned int questions_offset)
768577- cdef _write_answers_from_offset(self, object answer_offset)
86+@cython.locals(answers_written=cython.uint)
87+ cdef cython.uint _write_answers_from_offset(self, unsigned int answer_offset)
788879- cdef _write_records_from_offset(self, cython.list records, object offset)
89+@cython.locals(records_written=cython.uint)
90+ cdef cython.uint _write_records_from_offset(self, cython.list records, unsigned int offset)
809181- cdef _has_more_to_add(self, object questions_offset, object answer_offset, object authority_offset, object additional_offset)
92+ cdef bint _has_more_to_add(self, unsigned int questions_offset, unsigned int answer_offset, unsigned int authority_offset, unsigned int additional_offset)
82938394 cdef _write_ttl(self, DNSRecord record, object now)
8495@@ -93,23 +104,25 @@ cdef class DNSOutgoing:
9310494105 cdef _write_link_to_name(self, unsigned int index)
9510696- cpdef write_short(self, object value)
107+ cpdef write_short(self, cython.uint value)
9710898109 cpdef write_string(self, cython.bytes value)
99110111+@cython.locals(utfstr=bytes)
100112 cpdef _write_utf(self, cython.str value)
101113102114@cython.locals(
103115debug_enable=bint,
104116made_progress=bint,
105-questions_offset=object,
106-answer_offset=object,
107-authority_offset=object,
108-additional_offset=object,
109-questions_written=object,
110-answers_written=object,
111-authorities_written=object,
112-additionals_written=object,
117+has_more_to_add=bint,
118+questions_offset="unsigned int",
119+answer_offset="unsigned int",
120+authority_offset="unsigned int",
121+additional_offset="unsigned int",
122+questions_written="unsigned int",
123+answers_written="unsigned int",
124+authorities_written="unsigned int",
125+additionals_written="unsigned int",
113126 )
114127 cpdef packets(self)
115128