Arena Allocation in SBCL
github.com
github.com
arenas are x86_64 only, not sure how involved are ports, but there's at least a VOP, that as of right now exists only on x86_64. (the build obviously fails on other systems)
I'm trying it on m1, so I can build with
arch -arch x86_64 sh make.sh --with-system-tlabs
and then run with arch -arch x86_64 sh run-sbcl.sh
it's pretty raw, so for example allocating object larger than arena results in ldb. there's a lot of sample code in tests/arena.impure.lispand the simplest possible test code just to see what's up,
(gc :full t)
(room)
;;; 7,084,208 bytes for 36,307 simple-vector objects
(progn (make-array 10000000) (values))
(room)
;; 86,991,136 bytes for 36,080 simple-vector objects
(gc :full t)
;; 6,847,824 bytes for 35,865 simple-vector objects
(use-package :sb-vm)
(defvar a (new-arena 100000000))
(with-arena (a) (make-array 10000000) (values))
(room)
;; 7,050,080 bytes for 36,233 simple-vector objects
well, so at least we know the array is put somewhere. finally one calls (destroy-arena a), but you can still access the data, so presumably there's no checking involved, and being undisciplined about retaining arena pointers will create all kinds of interesting bugs.neat!
I guess it is best practice to bury arena management inside some sort of framework* and don't fiddle with them in business code.
*: Edit: more likely, a macro
Jai just seems to be going from strength to strength with arena-by-default.
The key insight is that a modern malloc isn’t terribly different from a modern GC: people seem to vastly overstate the difference IMHO.
Arenas are like a bumping nursery but better. I hope we keep seeing more of this.
Jai just throws you a bump-allocated heap arena with a (tunable) default bigger than 8MB that you can hit with idiomatic syntax in every basic block.
None of this is impossible in C or C++ or Rust or Java: but idiomatic defaults and notation matter.
Most per-method allocations should be pointer bumped in an arena (we’re already paying for page tables and a TLB, might as well get our money’s worth), and the languages just don’t encourage it.
std::allocator is just fine - it's no more and no less than a wrapper around malloc/free and that's what it really only needs to be. If you need a different allocation scheme that your workload is going to benefit from: (1) you first need to come up with it by finding out what scheme is going to benefit you, (2) you then implement it through a custom allocator.
> Most per-method allocations should be pointer bumped in an arena ... and the languages just don’t encourage it.
System malloc implementation will do that by themselves whenever they see fit. And this is not the programming language problem to begin with at all.
C++ new isn't required to call malloc()/free() per ISO C++, underlying OS APIs can be called instead, there are the whole allocator infrastrcture, and placement new as well.
I believe ITA Software's QPX (which now forms a major part of Google Flights' backend) uses CL.
That being said, I suppose if you're developing an internal API for a compiler/interpreter, your "users" could be other parts of the project rather than language users.
https://github.com/sbcl/sbcl/commit/7f65522a16d857e41aa61cd0...
I also had a local thread based pool I hand wrote for fixed sized objects that were generated en masse.
I did look at the boost library pools too.
> On-Topic: Anything that good hackers would find interesting. That includes more than hacking and startups. If you had to reduce it to a sentence, the answer might be: anything that gratifies one's intellectual curiosity.
https://en.m.wikipedia.org/wiki/Region-based_memory_manageme...
The SBCL implementation is a very self-documented example, which is helpful if you wish to make arena-based allocation available in your language.
Also, there is absolutely no requirement that HN submissions all qualify as newsworthy. As others have pointed out in this thread, the gist of what's considered appropriate is quite simple and broad: "Anything that good hackers would find interesting."
that is gross please do not refer to sbcl memory management features as 'yums'
Since when do HN submission have to be "newsworthy"? People regularly post old articles.
> If I submitted to HN a random documentation page from LWN or Linux kernel, it would surely not be #1.
If that page is particularly interesting and you're lucky, why not?
someone might have never heard of anything of the sort
someone might be interested to see lispers present a use case where they care about reaching down to the finer points of memory allocation in a language that typically benefits from being above that; see also the wealth of info on the garbage collector in the ocaml documentation
the number of users on this website who might get some sort of kick out of this link is nonzero which is the generally agreed-upon criterion for being worth posting
Begone pedant, and feast thine eyes on the surreal numbers [0]!
> In mathematics, the surreal number system is a totally ordered proper class containing not only the real numbers but also infinite and infinitesimal numbers, respectively larger or smaller in absolute value than any positive real number.
(Also, go look at the `fil` unit in TeX for a good practical application of this ;).)
This is more "create a separate arena where we can allocate a ton of stuff and then drop it without actually going through collector".
In fact, this is very similar to features provided in at least Symbolics Genera, which provided developer-created arenas as well.