Optimize drain logic to minimize memory usage