Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround Fable issue with active patterns
Issue: In some cases, Fable 2.1.12 hangs at compile time even as dotnet.exe grows to a a multi-gigabyte footprint. After consulting with Fable's creator, Alfonso Garcia-Caro, I decided to remove the reliance on F# compiler's magic for defining recursive data structures (via delayed initiatization). Even though the magic worked fine in .NET, it seemed to be confusing Fable, so I replaced it with code that explicitly did the same thing as the compiler magic: used stateful variables to implement recursive definitions. This was enough to prevent Fable from blowing up to multi-gigabyte footprints, and it was even though to allow compilation to terminate eventually (after 10x longer than usual), but I wanted to solve the perf problem too and make Fable compile my project quickly (~45 seconds instead 10 minutes). It turned out that the key here was *long* grammar productions, i.e. deeply-nested recursive active patterns. The solution was to define local, helper active patterns and reference those. For example, in Dice.fs, the (|SimpleRoll|_|) active pattern now has two helper patterns, LongSimpleRoll and MidSimpleRoll. Extracting LongSimpleRoll saved ~35 seconds of compile time, and extracting MidSimpleRoll saved ~4 seconds. (Prior to extraction, it was taking ~49 seconds to compile the project. Afterwards, it took ~11 seconds.) I also updated Fable version and Babel/Webpack versions in the process. This may have helped some; it's hard to tell, but it didn't hurt any so I'm checking it in.
- Loading branch information