improve memory consumption in write path