Open cjay opened 2 years ago
I'm not sure what you want to happen instead? You're generating an AST with roughly 2^19 nodes.
I expected use-sites of hoisted terms to behave like function calls do in other languages, so they would just be a named reference in the AST, with the name being the hash. Looks like my intuition was wrong there. Thinking a bit more about this, I realize the implementation of a hoisted thing would still have to be carried along with the hash, if the compile function should stay pure. So to prevent memory explosion, terms would need to deduplicate their hoisted subterms while being constructed. Maybe it would be possible, but not sure if it would speed up the compiler in normal use cases at all.
This isn't the issue here. There is no way to do what you're asking, because pbranch
fundamentally duplicates the AST. If you make pbranch
use a plet
, there probably will be no issue. What you're essentially asking for, is for an implicit plet
to be inserted. This is antithetical to the design of Plutarch. Rather than assuming it is Haskell, it is useful to understand the underlying model. It is beneficial to allow the programmer to have precise control over what is generated, rather than implicitly inserting plet
s.
I'd consider it a low priority issue, but we could add a pre-compile fold of the AST to check its size and report an error if it exceeds some ridiculous bound.
Now that I'm looking at the code again, I'm not sure why it's not hoisted.
Ah, the issue here is different I think. Things are being hoisted, but to do the hoisting, the huge AST has to be traversed. Maybe if we do the hoisting while generating the terms, it can me made more efficient.
@cjay Try compiling with -O2
.
Maybe also compile Plutarch with -O2
?
-O2
on the program was already in use, with the times from the comments. -O2
on Plutarch also seems to make no difference. Assuming I did this correctly, having the following in cabal.project
(and reloading nix develop):
package plutarch
ghc-options: -O2
@L-as - what's the status of this issue? Is it possible to fix this?
@kozross Haven't worked on this, but should be possible to fix. This is affecting you?
@L-as This is a problem we are running into with @cjay's work, so a fix would be great!
@kozross have the phoistAcyclic always be at the top level
Having 19 top-level definitions that call each other would change this? How? Because of CAF? If I remember correctly I tried with local let-bindings, at least that didn't improve compile time.
GHC will cache evaluations of top-level definitions.
A call hierarchy depth over 15 might be rare, but maybe this points to some deeper issue. I suppose hoists don't recognize hoisted sub-terms, instead hashing a fully inlined AST, or something like that? Note that sharing the sub-terms on the Haskell-level does not help.