diff options
author | Cheng Shao <astrohavoc@gmail.com> | 2022-09-09 17:45:45 +0000 |
---|---|---|
committer | Cheng Shao <astrohavoc@gmail.com> | 2022-11-16 09:16:29 +0000 |
commit | 08bf28819b78e740550a73a90eda62cce8d21c90 (patch) | |
tree | 38dd14258332f5fc8ca4798d37968723a0ad873b /rts | |
parent | 02d3511b8d248ea9429512830f8f17b31688a6a6 (diff) | |
download | haskell-08bf28819b78e740550a73a90eda62cce8d21c90.tar.gz |
base: make Foreign.Marshal.Pool use RTS internal arena for allocation
`Foreign.Marshal.Pool` used to call `malloc` once for each allocation
request. Each `Pool` maintained a list of allocated pointers, and
traverses the list to `free` each one of those pointers. The extra O(n)
overhead is apparently bad for a `Pool` that serves a lot of small
allocation requests.
This patch uses the RTS internal arena to implement `Pool`, with these
benefits:
- Gets rid of the extra O(n) overhead.
- The RTS arena is simply a bump allocator backed by the block
allocator, each allocation request is likely faster than a libc
`malloc` call.
Closes #14762 #18338.
Diffstat (limited to 'rts')
-rw-r--r-- | rts/Arena.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/rts/Arena.h b/rts/Arena.h index 49298713ab..8a7b304a7a 100644 --- a/rts/Arena.h +++ b/rts/Arena.h @@ -10,13 +10,13 @@ typedef struct _Arena Arena; // Start a new arena -RTS_PRIVATE Arena * newArena ( void ); +Arena * newArena ( void ); // Allocate memory in an arena -RTS_PRIVATE void * arenaAlloc ( Arena *, size_t ); +void * arenaAlloc ( Arena *, size_t ); // Free an entire arena -RTS_PRIVATE void arenaFree ( Arena * ); +void arenaFree ( Arena * ); // For internal use only: RTS_PRIVATE unsigned long arenaBlocks( void ); |