[Python-Dev] Speeding up CPython 5-10% (original) (raw)
Glenn Linderman v+python at g.nevcal.com
Wed Jan 27 15:46:15 EST 2016
- Previous message (by thread): [Python-Dev] Speeding up CPython 5-10%
- Next message (by thread): [Python-Dev] Speeding up CPython 5-10%
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 1/27/2016 12:37 PM, Yury Selivanov wrote:
MicroPython also has dictionary lookup caching, but it's a bit different to your proposal. We do something much simpler: each opcode that has a cache ability (eg LOADGLOBAL, STOREGLOBAL, LOADATTR, etc) includes a single byte in the opcode which is an offset-guess into the dictionary to find the desired element. Eg for LOADGLOBAL we have (pseudo code): CASE(LOADGLOBAL): key = DECODEKEY; offsetguess = DECODEBYTE; if (globaldict[offsetguess].key == key) { // found the element straight away } else { // not found, do a full lookup and save the offset offsetguess = dictlookup(globaldict, key); UPDATEBYTECODE(offsetguess); } PUSH(globaldict[offsetguess].elem); We have found that such caching gives a massive performance increase, on the order of 20%. The issue (for us) is that it increases bytecode size by a considerable amount, requires writeable bytecode, and can be non-deterministic in terms of lookup time. Those things are important in the embedded world, but not so much on the desktop. That's a neat idea! You're right, it does require bytecode to become writeable.
Would it?
Remember "fixup lists"? Maybe they still exist for loading function addresses from one DLL into the code of another at load time?
So the equivalent for bytecode requires a static table of offset_guess, and the offsets into that table are allocated by the byte-code loader at byte-code load time, and the byte-code is "fixed up" at load time to use the correct offsets into the offset_guess table. It takes one more indirection to find the guess, but if the result is a 20% improvement, maybe you'd still get 19%...
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160127/40458bb2/attachment.html>
- Previous message (by thread): [Python-Dev] Speeding up CPython 5-10%
- Next message (by thread): [Python-Dev] Speeding up CPython 5-10%
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]