Back to all reviewers

Use memory pools

oven-sh/bun
Based on 5 comments
Other

Reuse memory with buffer pools for temporary allocations instead of creating new buffers each time. This reduces memory allocation overhead and improves performance, especially for operations that frequently need temporary storage.

Performance Optimization Other

Reviewer Prompt

Reuse memory with buffer pools for temporary allocations instead of creating new buffers each time. This reduces memory allocation overhead and improves performance, especially for operations that frequently need temporary storage.

// Instead of this:
var link_target_buf: bun.PathBuffer = undefined;

// Use this:
const link_target_buf = bun.PathBufferPool.get();
defer bun.PathBufferPool.put(link_target_buf);

Using memory pools for buffers that are only needed temporarily during a function call helps avoid expensive allocation and deallocation cycles. The pattern of getting from a pool and deferring the return ensures the memory is properly recycled without leaking, even if the function returns early through different code paths.

5
Comments Analyzed
Other
Primary Language
Performance Optimization
Category

Source Discussions