Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posts/2023-08-29-allocations/index #19

Open
utterances-bot opened this issue Aug 29, 2023 · 2 comments
Open

posts/2023-08-29-allocations/index #19

utterances-bot opened this issue Aug 29, 2023 · 2 comments

Comments

@utterances-bot
Copy link

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

Copy link
Owner

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!

(I learned this from a Hadley tweet a long time ago but can't seem to locate the original discussion)

Copy link

jrosell commented Aug 30, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants