IntersectMBO / IntersectMBO/plutus
PIR case-of-case is exponential and causes OOMs
- Dominant language
- Haskell
- Stars
- 1.6k
- Forks
- 508
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 22
Description
### Summary
After updating to the latest `plutus-tx`, we noticed some significant regression in the instances generated by `PlutusTx.makeIsDataIndexed ''C [...]` .
Compilation times skyrocketed and memory usage is between 60-100GB of RAM (I have a lot of memory).
The issue seems to be the simplification process of the script compilation. For now, we reduced as much as possible the simplifier iterations with `PlutusTx.Plugin:max-simplifier-iterations-pir=1`. After that change, memory usage is back to normal.
I don't know exactly the issue, but I started by writing my own `UnsafeFromData` instance for `C` which resulted in the same issue. Then, I noticed that the amount of used memory seemed to be proportional to the number of constructors of C.
### Steps to reproduce the behavior
For a minimal reproductible example:
```
import PlutusTx qualified
import PlutusTx.Prelude hiding (Semigroup (..), unless)
import Prelude qualified as H
data C = A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R
PlutusTx.makeIsDataIndexed ''C [ ('A, 0) , ('B, 1) , ('C, 2) , ('D, 3) , ('E, 4) , ('F, 5) , ('G, 6) , ('H, 7) , ('I, 8) , ('J, 9) , ('K, 10) , ('L, 11) , ('M, 12) , ('N, 13) , ('O, 14) , ('P, 15) , ('Q, 16) , ('R, 17) ]
{-# INLINABLE validator #-}
validator ::
BuiltinData
-> BuiltinData
-> BuiltinData
-> Bool
validator d _ _ =
let !_ = PlutusTx.unsafeFromBuiltinData @C d
in True
unappliedValidator ::
PlutusTx.CompiledCode (PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> BuiltinUnit)
unappliedValidator =
$$(PlutusTx.compile [|| \d r c -> check $ validator d r c ||])
```
### Actual Result
_No response_
### Expected Result
_No response_
### Describe the approach you would take to fix this
_No response_
### System info
Plutus: 88ad493ad94ecdb34196f7a9aef558613bdee8b2
Contributor guide
Assessment
This issue has not been assessed yet.