-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
clarify common confusion about allocations #46383
Conversation
My understanding of what can be stack allocated and what can't is still fuzzy. Assuming the array can be stack allocated than my only issue is that heap allocated objects may require a system call or they may not.
|
Yes, heap allocations can sometimes be relatively cheap, but the point here is that (a) we count allocations when benchmarking because heap-allocating in an inner loop is often a performance bottleneck, (b) people need to have at least a crude idea of what kinds of things are typically heap-allocated (even though the precise rules are indeed fuzzy). If you want to talk about the details of the memory-allocation system, possible compiler optimizations that can sometimes stack-allocate mutable objects, and so on, I think that belongs in a separate document (e.g. a technical appendix all about memory allocation would be great). The goal of the performance tips document is to give some rules of thumb to ordinary programmers, who may barely know what a "heap" is (much less a free page). |
Most editors should have a feature for that. For example, vim is |
I was just editing it using the github interface. (I'm not sure why we need to linewrap at all for markdown files?) |
We mostly don't. But it usually just helps to keep the diff look more readable than just going for an entire paragraph. |
Okay to merge? |
What counts as an "allocation" seems to be a common point of confusion (e.g. does
1+1
"allocate" an integer for its result2
), so it seemed worthwhile to clarify somewhere what gets allocated on the heap.The performance tips seem as good a place as any for this, but I'm open to other suggestions.