rtfeldman / seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
BSD 3-Clause "New" or "Revised" License
5.37k stars 195 forks source link

immutable object causes rapid memory growth #281

Open chenjf5 opened 1 year ago

chenjf5 commented 1 year ago

nonMutatingArrayMethods adds many anonymous functions to each array, resulting in rapid memory growth. 2M data will increase to 50-80M. function makeMethodReturnImmutable(obj, methodName) { var currentMethod = obj[methodName]; addPropertyTo(obj, methodName, function() { return Immutable(currentMethod.apply(obj, arguments)); }); }

function banProperty(target, methodName) { addPropertyTo(target, methodName, function() { throw new ImmutableError("The " + methodName + " method cannot be invoked on an Immutable data structure."); }); }

crudh commented 1 year ago

@chenjf5 if you use the static syntax, https://github.com/rtfeldman/seamless-immutable#static-or-instance-syntax, it shouldn't do that.