Open utterances-bot opened 10 months ago
Over on Mastodon, June Choe points to the commits in R associated with this change https://fosstodon.org/@yjunechoe/110975018204561319
@MikeMahoney218 "Always pre-allocate your vectors" is a bit of an outdated dogma. Since v3.4, R already over-allocates memory by a small factor (x1.05) every time a vector needs to grow!
https://github.com/wch/r-source/commit/12aa371f88e5ece5015246e4f4b3e0b2b7f21639
https://github.com/wch/r-source/commit/37388191f5493825923b98246ec02e9b13ab1770
(I learned this from a Hadley tweet a long time ago but can't seem to locate the original discussion)
Hi Mike. I tried an even "devilish" approach using c and unlist and you can see that the results are similar https://gist.github.com/jrosell/ebb604e8c35a8665e2380ef3ea952464
I get the idea from @JosiahParry video about loops https://youtu.be/TdbweYvwnss?si=ho3NKWtBF-KW60HX
Mike Mahoney - Pre-allocating vectors is for nerds
Or rather: growing objects is inefficient. But it’s maybe not as big a deal as I’d believed.
https://www.mm218.dev/posts/2023-08-29-allocations/index.html