Inline Caching - Runtime Method Binding

Runtime Method Binding

The following ECMAScript function receives an object, invokes its toString-method and displays the results on the page the script is embedded in.

function dump(obj) { document.write(obj.toString); }

Since the type of the object is not specified and because of potential method overloading, it is impossible to decide ahead of time, which concrete implementation of the toString-method is going to be invoked. Instead, a dynamic lookup has to be performed at runtime. In language runtimes that do not employ some form of caching, this lookup is performed every time a method is invoked. Because methods may be defined several steps down the inheritance chain, a dynamic lookup can be an expensive operation.

To achieve better performance, many language runtimes employ some form of non-inline caching where the results of a limited number of method lookups are stored in an associative data structure. This can greatly increase performance, provided that the programs executed are "cache friendly" (i.e. there is a limited set of methods that is invoked frequently). This data structure is typically called the first-level method lookup cache.

Read more about this topic:  Inline Caching

Famous quotes containing the words method and/or binding:

    One of the grotesqueries of present-day American life is the amount of reasoning that goes into displaying the wisdom secreted in bad movies while proving that modern art is meaningless.... They have put into practise the notion that a bad art work cleverly interpreted according to some obscure Method is more rewarding than a masterpiece wrapped in silence.
    Harold Rosenberg (1906–1978)

    What is lawful is not binding only on some and not binding on others. Lawfulness extends everywhere, through the wide-ruling air and the boundless light of the sky.
    Empedocles 484–424 B.C., Greek philosopher. The Presocratics, p. 142, ed. Philip Wheelwright, The Bobbs-Merrill Co., Inc. (1960)