Haskell advices for optimize and reduce Plutus Script size and cpu and ram usage

Hello again,

I’m wondering in all the works-around to optimize and reduce the size of the scripts and resources utilization.

I’m working in a big project and I’m struggling with this runtime limitations.

I would love to be able to code the logic of any big idea or project. I believe this must be possible to do it with Cardano.

I’m not Haskell expert, so I might be falling in some beginner mistakes handling data types or code structures.

I read some articles:

1 -

https://plutus.readthedocs.io/en/latest/reference/writing-scripts/optimization.html?highlight=profiling

They mention:

  • Avoiding higher-order functions and closures.
  • Adding strictness on accumulators in recursive functions.
  • Common expression elimination.
  • Using error for faster failure.
  • Avoid monad do notation to handle pattern match failure: Can’t understand this one clearly.

2 - GitHub - Plutonomicon/plutarch-plutus: Typed eDSL for writing UPLC /ˈpluː.tɑːk/

I understand that this is about coding all again, with this language that is more low level and efficient that the Plutus libraries.

3 - contracts/dex/src/Minswap at main · CatspersCoffee/contracts · GitHub

I saw in the code of Minswap, that they convert the Plutus Script with Plutonomy (GitHub - well-typed/plutonomy: An optimizer for untyped plutus core)

import qualified Plutonomy

{-# INLINEABLE mkFactoryPolicy #-}
mkFactoryPolicy :: MintingPolicy
mkFactoryPolicy =
Plutonomy.optimizeUPLC $
Plutonomy.mintingPolicyToPlutus originalFactoryPolicy

But im not sure about the final code. How we can be sure that the code is reliable after it is passed trough Plutonomy.optimizeUPLC and also this is only compatible with specific older version of Plutus:

plutus-1efbb276e
plutus-4710dff2e
plutus-f680ac697 (cardano-node-1.35.1)

I would appreciate any help in this matter.

If you can share your experience codding big projects and solutions you fount that will mean a lot for me.

Thank you so much.

Regards, Manu