InvokeWithLayer optimization