2 days ago · Tech · 0 comments

Following up on yesterday’s post about benchmarking, Claude and I have made some improvements to asimpy. 1. Eliminate functools.partial in resume() Before, every time an event fired and needed to reschedule a waiting process, resume() did this: from functools import partial def resume(self, value=None): if not self._done: self._env.immediate(partial(self._loop, value)) partial is a C-level callable, so it is fast, but it still allocates a new object on every event completion. The fix stores the value directly on the process and schedules _loop without wrapping it: def resume(self, value=None): if not self._done: self._resume_value = value self._env.immediate(self._loop) def _loop(self): value = self._resume_value self._resume_value = None ... 2. Inline _add_waiter in _loop When a process parks on a pending event, the original code called through a method: yielded._add_waiter(self.resume) The inlined version writes directly to the event’s waiter slot: if v is _PENDING: w =…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.