Skip to content
  • Cheng Shao's avatar
    base: make Foreign.Marshal.Pool use RTS internal arena for allocation · 08bf2881
    Cheng Shao authored
    `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.
    08bf2881