Debian Codegraph @

pypy/module/_hpy_universal/ideas.txt

raw
1 ==================================================================
2 IRC conversation between anto and armin about handles destructors
3 ==================================================================
4
5 <antocuni> how do we implement HPyBytes_AsString() on pypy? We either need to pin the buffer or to make a copy
6 <antocuni> but we don't have any way in the current API to communicate when we can "close" it (i.e., unpin or free the copy)
7 [...]
8 <antocuni> arigato: what about this implementation of HandleManager.close()? http://paste.openstack.org/show/786900/
9 def close(self, index):
10 assert index > 0
11 self.handles_w[index] = None
12 if self.destructors[index] is not None:
13 for fn in self.destructors[index]:
14 fn()
15 self.destructors[index] = None
16 self.free_list.append(index)
17 <antocuni> you pay only an "if" in the common case
18
19 <arigato> yes, that's probably OK
20 <arigato> we can also tweak the various arrays (now three, handles_w, free_list and destructors) for cache efficiency
21
22 <antocuni> this is not seen by the JIT anyway, I suppose? So we don't even have to worry about the extra bridge
23 <antocuni> how?
24
25 <arigato> e.g. make a single array of Struct(handle, index). When the handle is free, "index" is the next item in the free list. When the handle is allocated, "index" is an integer that efficienty encodes which destructors to run (e.g. one bit per destructor)
26 <arigato> so the check for destructors in close() becomes a check "index != 0" that is from the same cache line as the "handle" we just wrote to
27 <arigato> just an idea. Maybe it's not worth it, because walking a large array of structs is significantly slower in the GC
28
29 <antocuni> ah, and every time you allocate a handle, you read the "next item in the free list" and stick it in HandleManager
30 <antocuni> "encodes which destructors to run": so you are proposing to have 64 different kind of destructors?
31
32 <arigato> yes, but it's unclear if this is better or worse than the free_list as a plain list like now
33 <arigato> yes, I'm suggesting we only need a small number of destructors
34
35 <antocuni> I suppose this is something which we can try later anyway, no need to complicate things now
36 <arigato> yes