numba / llvmlite

A lightweight LLVM python binding for writing JIT compilers
https://llvmlite.pydata.org/
BSD 2-Clause "Simplified" License
1.94k stars 322 forks source link

`fanout_raise` in `refpruning` algorithm doesn't work on this subtle case #1023

Closed dlee992 closed 7 months ago

dlee992 commented 11 months ago

Continue from https://github.com/numba/numba/issues/9213 Tested with 0.39.1. I feel latest version still has this issue.

I found a subtle case for refcounting, which our refpruning algorithm under ffi can't prune it. However, it should be in theory, since I think any path reaching raise block can be ignored?

image

Just want to make sure that you also think this's prunable. I do have a real case having this kind of pattern and have a workaround for this. Removing these refcounting calls can boost 5%~10% performance for my benchmark.

cc @sklam

sklam commented 10 months ago

However, it should be in theory, since I think any path reaching raise block can be ignored?

Yes, that's right. In other words, we pretend that the raise block has corresponding decrefs. The effect is that we allow the raise block to leak.