optimizing performance with stream