I’m using graphql PPX with wordpress data that’s generating a polymorphic variant which produces about 25 branches in a switch statement.
With the switch statement enabled, compilation takes about 20s with rescript build -w, changing only the one file.
If I only include one catchall branch in the switch, eg | _ => React.null it compiles in 65ms
Adding one branch after the other bumps it to 250ms, 290ms, 407ms, 595ms and so on, and by the time I’ve added all 25 branches I’m over 20s.
Would you create an issue with a self-contained single file that reproduces the issue (no graphql or other libraries, just the end result) in the rescript-compiler repo?
Generally speaking there’s a performance (and complexity) penalty to be paid when using polymorphic variants but this does not sound reasonable.
I will try creating a minimal repro, but I’ve played around a bit and no longer think this is directly related to the polyvar. I was able to get build times down to ~300ms by removing any instance where I was destructuring data in that file and replacing it by directly drilling down into the data structures.
It might be that the polyvar branches were just consuming data that was being destructured, and when those branches were removed, rescript optimized the destructured data away.