Skip to content

Instantly share code, notes, and snippets.

View c9r's full-sized avatar

Chris Sachs c9r

View GitHub Profile
@c9r
c9r / devirtualized.md
Created July 27, 2012 02:22
De-virtualized Collections

De-virtualized Collections

De-virtualizing abstract collections would increase performance and decrease bytecode bloat for common use cases–without tying the hands of implementors. Conceptually, operations on abstract collections become syntactic sugar for inlined code templates. You opt-in to dynamic behavior by choosing subtypes that override extension methods with virtual ones. The root collections then become an encapsulation of their elements, but not an abstraction over operations on those elements; you can still perform such operations on these collections, but the compiler statically binds the implementation rather than indirecting to the run-time type's vtable-provided version. Collection sub-families–parallel, non-strict, and the like–override generic extension methods with virtual ones, and any value statically typed to such a collection works in the usual object-oriented way.

Sample de-virtualized collection hierarchy

import collection.generic.CanBuildFrom
import language.im