On preserving term sharing in the Erlang virtual machine
暂无分享,去创建一个
In programming language implementations, one of the most important design decisions concerns the underlying representation of terms. In functional languages with immutable terms, the runtime system can choose to preserve sharing of subterms or destroy sharing and expand terms to their flattened representation during certain key operations. Both options have pros and cons. The implementation of Erlang in the Erlang/OTP system from Ericsson has so far opted for an implementation where sharing of subterms is not preserved when terms are copied (e.g., when sent from one process to another or when used as arguments in spawns).
In this paper we describe our experiences and argue through examples why flattening terms during copying is not a good idea for a language like Erlang. More importantly, we propose a sharing-preserving copying mechanism for Erlang/OTP and describe a publicly available complete implementation of this mechanism. Performance results show that, even in extreme cases where no subterms are shared, this implementation has a reasonable overhead which is negligible in practice. In cases where shared subterms do exist, perhaps accidentally, the performance savings can be substantial.
[1] Iain D. Craig,et al. Virtual machines , 2005 .
[2] Konstantinos Sagonas,et al. On Using Erlang for Parallelization - Experience from Parallelizing Dialyzer , 2012, Trends in Functional Programming.
[3] Chris J. Cheney. A nonrecursive list compacting algorithm , 1970, Commun. ACM.
[4] Mikael Pettersson. A staged tag scheme for Erlang , 2000 .