Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Copying large objects like lists […] can be costly in both time and memory.

> modify[ing] objects in place […] improves performance by avoiding the overhead of allocating and populating new structures.

AFAIK the poor performance of list copies (demonstrated in the article by a million-element list taking 10ms) doesn’t come from memory allocation nor from copying the contents of the list itself (in this case, a million pointers).

Rather it comes from the need to chase all of those pointers, accessing a million disparate memory locations, in order to increment each element’s reference count.



Yeah. A more nuanced approach is that you should copy things that don't consist of lots and lots of references to other things, and you should mutate things that are mostly references to other structures.

Which means, eventually, designing your data structures so you generally have two types of structures: one which isn't full of pointers, and one which mostly is.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: