Skip to content

Commit

Permalink
Speedups: no cinit, no pickling (#2851)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
black-sliver authored Feb 21, 2024
1 parent 7fc159c commit 17c7391
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions _speedups.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 17c7391

Please sign in to comment.