---
title: "optimizeIndirectCommandBuffer(_:range:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlblitcommandencoder/optimizeindirectcommandbuffer(_:range:)"
---

# optimizeIndirectCommandBuffer(_:range:)

Encodes a command that can improve the performance of a range of commands within an indirect command buffer.

## Declaration

```swift
func optimizeIndirectCommandBuffer(_ buffer: any MTLIndirectCommandBuffer, range: Range<Int>)
```

## Parameters

- `buffer`: An indirect command buffer the command optimizes.
- `range`: A range of commands within indirectCommandBuffer.

## Discussion

Discussion This command can reduce the time it takes the GPU to run the commands within an indirect command buffer by removing its redundancies. For example, an indirect command buffer may have empty commands or commands that duplicate identical state. Redundancies like these can come from multiple compute functions that encode commands in parallel, which can sometimes reset commands or configure identical states multiple times. important: You can only run optimized commands by using the entire range. Otherwise, starting or ending within an optimized range may result in unexpected behavior. You can’t run any commands that start or end at an index within that range, or that cross into another optimized range. However, you can reuse the range you optimize by resetting it and then encoding new commands to it.

## See Also

### Managing indirect command buffers

- [copyIndirectCommandBuffer(_:sourceRange:destination:destinationIndex:)](metal/mtlblitcommandencoder/copyindirectcommandbuffer(_:sourcerange:destination:destinationindex:).md)
- [resetCommandsInBuffer(_:range:)](metal/mtlblitcommandencoder/resetcommandsinbuffer(_:range:).md)
