Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-12 Thread Jeroen Demeyer
On 2019-03-08 22:16, Martin Bammer wrote: Hi, what about the idea that the interpreter preallocates and preinitializes the tuples and dicts for function calls where possible when loading a module? The basic premise here is wrong: function calls using the METH_FASTCALL convention don't need t

Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-10 Thread Ben Rudiak-Gould
On Fri, Mar 8, 2019 at 6:23 PM Steven D'Aprano wrote: > A sets the argument tuple to (1, 2) > B sets the argument tuple to (2, 3) > B calls spam() > A calls spam() # Oops! I'm pretty sure the idea was to have constant tuples (1, 2) and (3, 4) in the module instead of LOAD_CONST 1/

Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-09 Thread Serhiy Storchaka
08.03.19 23:16, Martin Bammer пише: what about the idea that the interpreter preallocates and preinitializes the tuples and dicts for function calls where possible when loading a module? Before calling a function then the interpreter would just need to update the items which are dynamic and then

Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-09 Thread Serhiy Storchaka
09.03.19 03:02, Greg Ewing пише: Martin Bammer wrote: what about the idea that the interpreter preallocates and preinitializes the tuples and dicts for function calls where possible when loading a module? This would not be thread-safe. Locking would be needed around uses of the preallocated

Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-09 Thread Martin Bammer
Ok right. There are some details which need to modify the idea: - Thread safety: Instead of locking the thread id could be saved in the object and then checked when the object is used. If the thread id is wrong then a new object must be created. I think there is no additional locking necessary beca

Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-09 Thread Martin Bammer
Thread safety is not a problem here because of the GIL. Am Sa., 9. März 2019 um 02:03 Uhr schrieb Greg Ewing < greg.ew...@canterbury.ac.nz>: > Martin Bammer wrote: > > > what about the idea that the interpreter preallocates and preinitializes > > the tuples and dicts for function calls where poss

Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-08 Thread Steven D'Aprano
On Fri, Mar 08, 2019 at 10:16:02PM +0100, Martin Bammer wrote: > Hi, > > what about the idea that the interpreter preallocates and > preinitializes the tuples and dicts for function calls where possible > when loading a module? That's an implementation detail. CPython may or may not use tuples

Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-08 Thread Greg Ewing
Martin Bammer wrote: what about the idea that the interpreter preallocates and preinitializes the tuples and dicts for function calls where possible when loading a module? This would not be thread-safe. Locking would be needed around uses of the preallocated objects, and that might take away s

[Python-ideas] Preallocated tuples and dicts for function calls

2019-03-08 Thread Martin Bammer
Hi, what about the idea that the interpreter preallocates and preinitializes the tuples and dicts for function calls where possible when loading a module? Before calling a function then the interpreter would just need to update the items which are dynamic and then call the function. Some exa