Skip to content

base: make Foreign.Marshal.Pool use RTS internal arena for allocation

Cheng Shao requested to merge TerrorJack/ghc:base-pool-rts-arena into master

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 (closed) #18338 (closed).

Merge request reports