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

clarify common confusion about allocations #46383

Merged
merged 3 commits into from
Oct 10, 2022
Merged

Conversation

stevengj
Copy link
Member

What counts as an "allocation" seems to be a common point of confusion (e.g. does 1+1 "allocate" an integer for its result 2), 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.

@stevengj stevengj added the docs This change adds or pertains to documentation label Aug 17, 2022
@oscardssmith oscardssmith requested a review from chflood August 19, 2022 19:42
@chflood
Copy link
Member

chflood commented Aug 19, 2022

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.

  1. Our first choice is to use a free list for an already dedicated page.
  2. Our second choice is to use one of our free pages.
  3. Our third choice is to call malloc which may have some free pages available. (Malloc is clever about batching requests)
  4. So they only time we go out for an official system call is when none of those succeeded.

@stevengj
Copy link
Member Author

stevengj commented Sep 1, 2022

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).

@vtjnash
Copy link
Member

vtjnash commented Sep 1, 2022

(grr, manual linewrapping)

Most editors should have a feature for that. For example, vim is :set textwidth=92 (e.g.) then gwip (go wrap in paragraph). Or VSCode has a setting for "Word Wrap Column", though I don't know how you are supposed to trigger it.

@stevengj
Copy link
Member Author

stevengj commented Sep 1, 2022

I was just editing it using the github interface. (I'm not sure why we need to linewrap at all for markdown files?)

@vtjnash
Copy link
Member

vtjnash commented Sep 1, 2022

We mostly don't. But it usually just helps to keep the diff look more readable than just going for an entire paragraph.

@stevengj
Copy link
Member Author

stevengj commented Oct 4, 2022

Okay to merge?

@KristofferC KristofferC merged commit 18cbaba into master Oct 10, 2022
@KristofferC KristofferC deleted the stevengj-patch-1 branch October 10, 2022 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants