Wed 31 May 2006
Optimizing OO With Type Feedback
Posted by dkaz under Python, Programming
Lambda the Ultimate “Type inference in Python” discussion links to a very interesting paper on Type Feedback, an optimization technique for OO programs that was unfamiliar to me before today.
An excerpt from the paper explains the idea of Type Feedback at a high-level:
The key idea of type feedback is to extract type information from previous executions and feed it back to the compiler. This feedback can happen dynamically (i.e., while the program is running) or statically (after execution completed, as in traditional profile-based optimization). Type feedback uses an instrumented version of a program to record the program’s type profile, i.e., a list of receiver classes (and, optionally, their frequencies) for every single call site in the program. To obtain the type profile, the standard method dispatch mechanism is extended in some way to record the desired information, e.g., by keeping a table of receiver classes per call site.
Based on the type feedback information, the compiler can predict likely receiver classes. For example, if type feedback indicates that obj’s class always was Point, the compiler could transform the call obj->moveTo(0, 0) into the following code:
if (obj->class == #Point) {
/* inlined copy of Point::moveTo */
obj->x = obj->y = 0;
} else {
/* handle non-Point case here */
}
