Move optimization for member op values
Summary:
When setting an element in an array, we call a native helper (that inc-refs the value) and then usually dec-ref the result (because the assignment result doesn't get used). We can avoid these two refcounting ops by creating a new helper that moves the value in place.
The new setMove operator on arrays has the following semantics (but for most array types, is implemented in a better way):
- Execute the normal set(k, v) operation
- Dec-ref the value v
- If the array was copied or escalated, def-ref the old array
These ops are guaranteed not to destroy the value. In irgen, we emit an inc-ref of the value after using this operation. If it's followed by a dec-ref, refcount-ops easily annihilates the two. We also have to modify consumesReference to tell refcount-opts about what's going on with these values.
This diff is a win on its own, but it should be even better with Michael's work to use specific ArraySet / DictSet ops instead of generic SetElems and to avoid the vtable dispatch. Since the new helper is a single virtual method on ArrayData, if we know the kind, we can call it directly.
Reviewed By: mofarrell
Differential Revision:
D18629174
fbshipit-source-id:
1e14bd13a7b0a70a17a39c86135f24ca291ccc32