<div dir="ltr"><p style="margin:0px;white-space:pre-wrap">Hi,</p>
<p style="margin:0px;white-space:pre-wrap">what about the idea that the interpreter preallocates and preinitializes the </p>
<p style="margin:0px;white-space:pre-wrap">tuples and dicts for function calls where possible when loading a module?</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">Before calling a function then the interpreter would just need to update the </p>
<p style="margin:0px;white-space:pre-wrap">items which are dynamic and then call the function.</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">Some examples:</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">msgpack.unpackb(b'\x93\x01\x02\x03', use_list=False, raw=False)</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">The above function call needs a tuple with 1 entry and a dict with 2 entries.</p>
<p style="margin:0px;white-space:pre-wrap">All entries are constant. So in this case the interpreter can immediately </p>
<p style="margin:0px;white-space:pre-wrap">execute the function call.</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">Without the optimization the interpreter would need to:</p>
<p style="margin:0px;white-space:pre-wrap">- create new tuple (allocate memory)</p>
<p style="margin:0px;white-space:pre-wrap">- write constant into first tuple index.</p>
<p style="margin:0px;white-space:pre-wrap">- create dict (allocate memory)</p>
<p style="margin:0px;white-space:pre-wrap">- add key+value</p>
<p style="margin:0px;white-space:pre-wrap">- add key+value</p>
<p style="margin:0px;white-space:pre-wrap">- call function</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">Another example:</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">foo(bar, 3, 5, arg1=bar1, arg2=True)</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">The above needs a tuple with 3 entries. 2 of them are constant. And a dict</p>
<p style="margin:0px;white-space:pre-wrap">with 2 entries. 1 of them is constant.</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">With the optimization:</p>
<p style="margin:0px;white-space:pre-wrap">- write bar into first tuple index.</p>
<p style="margin:0px;white-space:pre-wrap">- replace first key+value pair in the dict.</p>
<p style="margin:0px;white-space:pre-wrap">- call function</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">Without the optimization:</p>
<p style="margin:0px;white-space:pre-wrap">- create new tuple (allocate memory)</p>
<p style="margin:0px;white-space:pre-wrap">- write bar into first tuple index.</p>
<p style="margin:0px;white-space:pre-wrap">- write constant into second tuple index.</p>
<p style="margin:0px;white-space:pre-wrap">- write constant into third tuple index.</p>
<p style="margin:0px;white-space:pre-wrap">- create dict (allocate memory)</p>
<p style="margin:0px;white-space:pre-wrap">- add key+value</p>
<p style="margin:0px;white-space:pre-wrap">- add key+value</p>
<p style="margin:0px;white-space:pre-wrap">- call function</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">If this idea is possible to implement I assume the function calls would </p>
<p style="margin:0px;white-space:pre-wrap">receive a great speed improvment.</p>
<p style="margin:0px;white-space:pre-wrap"><br></p>
<p style="margin:0px;white-space:pre-wrap">Best regards,</p>
<p style="margin:0px;white-space:pre-wrap">Martin</p>
<p style="margin:0px;white-space:pre-wrap"><br></p></div>