generateLayer optimization.