From 17c73916b70c2a7cf103f8ee0522ec83d5f5b0a9 Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Wed, 21 Feb 2024 08:53:54 +0100 Subject: [PATCH] Speedups: no cinit, no pickling (#2851) * Speedups: remove unnecessary cinit This was meant for (memory) safety, but cython docs clearly state that this is done automatically. The code generated for cinit with args is what triggers a 'possible null deref' in clang's static analyzer, so by removing cinit, we can now use static analysis. * Speedups: disable pickling ... ... of LocationStore and internal classes. This reduces code size and avoids accidentally pickling them. --- _speedups.pyx | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/_speedups.pyx b/_speedups.pyx index 9bf25cce..b4167ec5 100644 --- a/_speedups.pyx +++ b/_speedups.pyx @@ -48,6 +48,7 @@ cdef struct IndexEntry: size_t count +@cython.auto_pickle(False) cdef class LocationStore: """Compact store for locations and their items in a MultiServer""" # The original implementation uses Dict[int, Dict[int, Tuple(int, int, int]] @@ -78,18 +79,6 @@ cdef class LocationStore: size += sizeof(self._raw_proxies[0]) * self.sender_index_size return size - def __cinit__(self, locations_dict: Dict[int, Dict[int, Sequence[int]]]) -> None: - self._mem = None - self._keys = None - self._items = None - self._proxies = None - self._len = 0 - self.entries = NULL - self.entry_count = 0 - self.sender_index = NULL - self.sender_index_size = 0 - self._raw_proxies = NULL - def __init__(self, locations_dict: Dict[int, Dict[int, Sequence[int]]]) -> None: self._mem = Pool() cdef object key @@ -281,6 +270,7 @@ cdef class LocationStore: entry.location not in checked]) +@cython.auto_pickle(False) @cython.internal # unsafe. disable direct import cdef class PlayerLocationProxy: cdef LocationStore _store