Inline caching

Uses your system voice; voice and rate in settings.

Q17082756Snapshot

≈ 3 min read

Names in other languages

  • EnglishInline caching
  • فارسینهان‌سازی درخط
  • 한국어인라인 캐싱
  • 中文内联缓存
  • 繁體中文線上暫存

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

Inline caching is an optimization technique employed by some language runtimes, and first developed for Smalltalk. The goal of inline caching is to speed up runtime method binding by remembering the results of a previous method lookup directly at the call site. Inline caching is especially useful for dynamically typed languages where most if not all method binding happens at runtime and where virtual method tables often cannot be used.

Inline caching is an optimization technique employed by some language runtimes, and first developed for Smalltalk. The goal of inline caching is to speed up runtime method binding by remembering the results of a previous method lookup directly at the call site. Inline caching is especially useful for dynamically typed languages where most if not all method binding happens at runtime and where virtual method tables often cannot be used. 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 are invoked frequently). This data structure is typically called the first-level method lookup cache. var values = [1, "a", 2, "b", 3, "c", 4, "d"]; for (var i in values) { document.write(values[i].toString()); } Again, the method toString is invoked on an object whose type is not known in advance. More importantly though, the type of the object changes with every iteration of the surrounding loop. A naive implementation of monomorphic inline caching would therefore constantly cycle through the "uninitialized" and "monomorphic" states. In order to prevent this from happening, most implementations of monomorphic inline caching support a third state often referred to as the "megamorphic" state. This state is entered when a particular call site has seen a predetermined number of different types. Once a call site has entered the "megamorphic" state, it will behave just as it did in the "uninitialized" state with the exception that it will not enter the "monomorphic" state ever again (some implementations of monomorphic inline caching will change "megamorphic" call sites back to being "uninitialized" after a certain amount of time has passed or once a full garbage collection cycle is performed). ==See also== Memoization

Text derived from https://en.wikipedia.org/w/index.php?oldid=1313975464 under CC BY-SA 4.0; modifications have been made.

Provenance

snapshot inline-caching-1854342-3bfba93d40759665 · hash 3bfba93d4075966570559ad2f7c884d42f95c8e58263a12110dcbcd4f54dfbd7 · captured 1759105817.0 · version history

Cite this page as: encyclopegia.org, “Inline caching”, snapshot inline-caching-1854342-3bfba93d40759665. https://encyclopegia.org/a/inline-caching