I had the same issue for my bot in rust (Possible compilation timeout for Rust (on LoCaM))
I tried for one week many tweaks but with inconsistent short term results. In the end, the only working long term ‘fix’ was a complete rewrite with simpler data structure and less abstraction.
I hope you don’t have to go this far