On 23 Feb 2015, at 21:15, Mariano Martinez Peck <marianopeck@gmail.com> wrote:On Fri, Feb 20, 2015 at 5:48 AM, Cl��ment Bera <bera.clement@gmail.com> wrote:It depends on your OrderedCollection implementation.OrderedCollection has a variable size in memory. When instantiated, it has for example 10 slots, and if you have more than 10 objects, it needs to change its size to hold more slots.I thought that was the case too, but I cannot find in code what you say.
The current implementation relies on an indirection to an array, when the array overflows, the orderedCollection allocates a new bigger array and copy the slots from the existing array. There are some heuristics on array size to avoid having to grow the array too often.If you want the shallowCopy to work, you have to use the old implementation of OrderedCollection, which encodes in its field directly the values it holds. In this case however when the collection overflows you create a new orderedCollection so you need to use #become: to migrate references to the old orderedCollection to the new one. This used to be a bad idea because the become primitive was slow, but since we have Spur, it may be relevant to look at it again. This old implementation is more memory efficient too.