Avoid unnecessary memory allocations, copies, and inefficient memory usage patterns that can impact performance. This includes several key practices:

Avoid unnecessary allocations:

Optimize parameter passing:

Pre-allocate when size is known:

// Instead of letting vector grow dynamically
kj::Vector<kj::Promise<void>> promises;
// Reserve space when size is known
promises.reserve(filenames.size());

Choose efficient memory usage patterns:

These optimizations are particularly important in hot paths or when processing large amounts of data, as small inefficiencies can compound significantly.