3 ms·
Python doesn't do code analysis to determine when it's effectively doing obj.refs++; obj.refs-- repeatedly. This sort of analysis is useful, and if the interpr
by ori_b 16y ago
Python doesn't do code analysis to determine when it's effectively doing obj.refs++; obj.refs-- repeatedly.
This sort of analysis is useful, and if the interpreter had been designed to do any optimization along with jitting, would probably come nearly for free. Reference counting could be far far cheaper than it is in python. (How much cheaper? I don't know - it'd need work to figure it out)
- sb 16y agoRecently, there has been some work on removing redundant reference count operations in the Python interpreter. The following paper describes how it can be done: http://portal.acm.org/citation.cfm?id=1869631.1869633 http://portal.acm.org/citation.cfm?id=1869631.1869633. Regarding the performance impact of reference counting, the following facts are important: - Switching from immediate reference counting to deferred reference counting (L.P. Deutsch and D.G. Bobrow, 1976 [1]) eliminates about 90pct of all reference count operations in Smalltalk (Berkeley Smalltalk '82, that is) [2] - A very good account of reference counting can be found in either Dave Ungar's excellent PhD thesis [3] and Dave Ungar and Dave Patterson's in-depth analysis of Smalltalk performance [4]. [1] An efficient, incremental, automatic garbage collector (http://www.cs.umass.edu/~emery/classes/cmpsci691s-fall2004/papers/p522-deutsch.pdf http://www.cs.umass.edu/~emery/classes/cmpsci691s-fall2004/p...) [2] High performance storage reclamation in an object-based memory system (http://techreports.lib.berkeley.edu/accessPages/CSD-84-167.html http://techreports.lib.berkeley.edu/accessPages/CSD-84-167.h...) [3] The Design and Evaluation of A High Performance Smalltalk System (http://www.eecs.berkeley.edu/Pubs/TechRpts/1986/5376.html http://www.eecs.berkeley.edu/Pubs/TechRpts/1986/5376.html) [4] Berkeley Smalltalk: Who knows where the time goes? (Chapter 11 of http://www.iam.unibe.ch/~ducasse/FreeBooks/BitsOfHistory/ http://www.iam.unibe.ch/~ducasse/FreeBooks/BitsOfHistory/)
- rayiner 16y agoThis sort of analysis does not come easily. Say you have: def bar(): return some_constructor() def foo(): b = bar() Here the decrement is in bar() and the increment is in foo(). You have no way to elide the operation without doing inter-procedural analysis, which is hard.
- ori_b 16y agoYou don't need to catch all the cases to see a big improvement. Just the most common ones.
- rayiner 16y agoThe problem is in a language like Python, where everything is broken up into little functions, you're not going to catch the most common uses without doing inter-procedural analysis.