[Mlir-commits] [mlir] [MLIR][Python] Improve Iterator performance. Don't `throw` in `dunderNext` methods. (PR #175377)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jan 13 07:52:24 PST 2026


MaPePeR wrote:

Thanks for the review again!

I multiplied the `number` by 10 to reduce variance a bit and run the "benchmark" again:

```
b77f7df49 with count=10:                500 loops, best of 5: 5.89 msecs per loop, worst: 5.9 msecs per loop
b77f7df49 with count=2:                5000 loops, best of 5: 0.482 msecs per loop, worst: 0.483 msecs per loop
281d10ef0 (this branch) with count=10:  500 loops, best of 5: 4.9 msecs per loop, worst: 4.94 msecs per loop
281d10ef0 (this branch) with count=2:  5000 loops, best of 5: 0.414 msecs per loop, worst: 0.416 msecs per loop
```

So for count=10 the improvement is 1-4.9/5.8 ≈ 16.8% and for count=2 the improvement is 1-0.414/0.482 ≈ 14.1%.

I think the reason is, that for `count=10` there are 10 + 10² `scf.for` operations generated. For `count=2` its only 2 + 2². So `count=10` throws more exceptions per run, because there are more blocks/regions/ops. But I'm probably not the right person to interpret this.

Also added your suggested comment to all the functions and removed an not required `cast`, so I consider this PR done until further comments.

https://github.com/llvm/llvm-project/pull/175377


More information about the Mlir-commits mailing list