Well, based on some examination of the code, I'd expect RemoveAt
(Remove
has to find the item first) and Insert
to be pretty much the same as Add
. The basic principle is the same. The thing I'd be more worried about is the pattern of memory usage and things like that - if you use a few ImmutableList
s side-by-side and do a lot of adding and removing, I'd expect you might quickly run into data locality issues, which would cause your performance to plummet. AddRange
is mostly a shortcut, it really only calls a bunch of Node.Add
s anyway, saving some overhead, but not much. There's also a lot of recursion.
ImmutableArray
would not cause that, because it always creates a whole new array and copies the old array over. So it will cause a lot of memory copying and allocations / collections, but it will also be more stable performance-wise - access time doesn't change with usage, and there aren't even any shortcuts when modifying the array, you always have to copy all the items. This also means that adding multiple items simply has to be done with AddRange
- the performance difference will be enormous. Add
is internally implemented using Insert
, so it's the same thing at the moment. In other words, all the change operations are o/O(n), while read is o/O(1).
All in all, ImmutableList
is more concerned about frequent changes and sacrifices read performance, while ImmutableArray
is mostly useful for a lot of reads, and relatively few changes.