problem with yesod, persist and enumerations

Hi all, I'm running into significant compile-time performance problems with a relatively simple database. This email describes a small example using a default project from the yesod scaffolding tool. Trying to compile the project causes ghc to consume several GB of memory on my system (eventually I have to kill it). I'm running GHC 7.0.3 and the current yesod beta. It's definitely possible that I'm doing something very stupid - any help would be appreciated. The example just involves adding one table to a default project's database. Suppose I want to add a table with 15 columns, each holding a US State or Nothing (a little silly, but in my real application the data is more interesting). To do this, I'll make a datatype to list the US states, give it a PersistField instance with some help from the Enum typeclass, and add the table. In the Model.hs file, I add an import line:
import Database.Persist.Base
And then I define my representation of the US State codes:
data USStateCode = AL | AK | AS | AZ | AR | CA | CO | CT | DE | DC | FM | FL | GA | GU | HI | ID | IL | IN | IA | KS | KY | LA | ME | MD | MA | MI | MN | MS | MO | MT | NE | NV | NH | NJ | NM | NY | NC | ND | MP | OH | OK | OR | PW | PA | PR | RI | SC | SD | TN | TX | UT | VT | VI | VA | WA | WV | WI | WY deriving (Read, Show, Eq, Ord, Enum)
instance PersistField USStateCode where toPersistValue = PersistInt64 . toEnum . fromEnum
fromPersistValue (PersistInt64 a) = Right $ toEnum $ fromEnum a fromPersistValue _ = Left "error"
sqlType _ = SqlInteger
And I add the table to the bottom of my entities file:
MyTable st1 USStateCode Maybe st2 USStateCode Maybe st3 USStateCode Maybe st4 USStateCode Maybe st5 USStateCode Maybe st6 USStateCode Maybe st7 USStateCode Maybe st8 USStateCode Maybe st9 USStateCode Maybe st10 USStateCode Maybe st11 USStateCode Maybe st12 USStateCode Maybe st13 USStateCode Maybe st14 USStateCode Maybe st15 USStateCode Maybe
Making these changes to a default project and then compiling causes the problems I described above. Can someone fill me on on a better way to add a table holding some enumerated data? Thanks! --Chris

On Sat, Apr 16, 2011 at 5:54 PM, Chris Casinghino < chris.casinghino@gmail.com> wrote:
On Sat, Apr 16, 2011 at 10:45 AM, Greg Weber
wrote: Are you compiling with the development server or doing a cabal build/
I'm doing a cabal build. To reproduce this, I run (cabal configure && cabal build) from the command line in the project directory.
I can confirm that this happens. However, it *only* happens when building with cabal. When building with "ghc --make", using runghc or wai-handler-devel, everything works fine. So I tried compiling with "ghc --make -O", and sure enough the same bug appeared. I don't think there's anything we can do in the libraries to avoid this, it looks like a bug in GHC. You can modify your ghc-options line in the cabal file to pass in "-O0" to disable optimizations, though this is obviously not optimal (bad pun intended). I think we need to report this to the GHC team. I know virtually nothing about GHC internals, but in case this means something to someone else, here's some of the output from "ghc --make -O -v test.hs": *** Simplify: *** CorePrep: *** ByteCodeGen: *** Desugar: Result size = 8699 *** Simplifier SimplMode {Phase = InitialPhase [Gentle], no inline, rules, eta-expand, no case-of-case} max-iterations=4: Result size = 9841 Result size = 9797 Result size = 9797 *** Specialise: Result size = 9797 *** Float out(FOS {Lam = Just 0, Consts = True, PAPs = False}): Result size = 13259 *** Float inwards: Result size = 13259 *** Simplifier SimplMode {Phase = 2 [main], inline, rules, eta-expand, case-of-case} max-iterations=4: Result size = 677741 Result size = 850762 Result size = 1028928 Result size = 1028928 *** Simplifier SimplMode {Phase = 1 [main], inline, rules, eta-expand, case-of-case} max-iterations=4: Result size = 1026905 Result size = 1026876 Result size = 1026876 *** Simplifier SimplMode {Phase = 0 [main], inline, rules, eta-expand, case-of-case} max-iterations=4: Michael

I worry about the future of haskell (ghc). I know at least three problems
- not memory releasing
- optimization issues
- multi-core execution issue (works bad with more than 4 core)
sadly ... (
2011/4/16 Michael Snoyman
On Sat, Apr 16, 2011 at 5:54 PM, Chris Casinghino < chris.casinghino@gmail.com> wrote:
On Sat, Apr 16, 2011 at 10:45 AM, Greg Weber
wrote: Are you compiling with the development server or doing a cabal build/
I'm doing a cabal build. To reproduce this, I run (cabal configure && cabal build) from the command line in the project directory.
I can confirm that this happens. However, it *only* happens when building with cabal. When building with "ghc --make", using runghc or wai-handler-devel, everything works fine. So I tried compiling with "ghc --make -O", and sure enough the same bug appeared.
I don't think there's anything we can do in the libraries to avoid this, it looks like a bug in GHC. You can modify your ghc-options line in the cabal file to pass in "-O0" to disable optimizations, though this is obviously not optimal (bad pun intended). I think we need to report this to the GHC team.
I know virtually nothing about GHC internals, but in case this means something to someone else, here's some of the output from "ghc --make -O -v test.hs":
*** Simplify: *** CorePrep: *** ByteCodeGen: *** Desugar: Result size = 8699 *** Simplifier SimplMode {Phase = InitialPhase [Gentle], no inline, rules, eta-expand, no case-of-case} max-iterations=4: Result size = 9841 Result size = 9797 Result size = 9797 *** Specialise: Result size = 9797 *** Float out(FOS {Lam = Just 0, Consts = True, PAPs = False}): Result size = 13259 *** Float inwards: Result size = 13259 *** Simplifier SimplMode {Phase = 2 [main], inline, rules, eta-expand, case-of-case} max-iterations=4: Result size = 677741 Result size = 850762 Result size = 1028928 Result size = 1028928 *** Simplifier SimplMode {Phase = 1 [main], inline, rules, eta-expand, case-of-case} max-iterations=4: Result size = 1026905 Result size = 1026876 Result size = 1026876 *** Simplifier SimplMode {Phase = 0 [main], inline, rules, eta-expand, case-of-case} max-iterations=4:
Michael
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel
-- Best regards, Cheshkov Anton Phone: +7 909 005 18 82 Skype: cheshkov_anton

I think you've got very little to fear about here. The GHC team is amazingly
responsive, and addresses issues quickly. For the three that you're bringing
up:
1. It's debatable whether GHC is doing the wrong thing here, and I *think*
there's work going on now to "fix" this problem. (I would also like to see
the current behavior changed.)
2. Well, I just wrote the bug report, so we can't expect much from them
here. But if you think there are no other compilers in wide usage today that
suffer from bugs, you're in for a rude awakening.
3. I'm bad at analogies, so I'll just put it this way: have you seen the
Perl/Python/Ruby multi-threading model? We've got nothing to complain about
here. Plus, there's active work to make it even better.
<prediction>Basically, if you write code today in Haskell versus
Perl/Python/Ruby for multithreading, you'll scale to four cores much better
than they will. And six months from now, you'll scale to eight cores as
well, without changing a line of code.</prediction>
That's not to say you shouldn't bring up your concerns, but I think that
from this perspective Haskell and GHC are in good shape.
Michael
On Sat, Apr 16, 2011 at 8:35 PM, Anton Cheshkov
I worry about the future of haskell (ghc). I know at least three problems
- not memory releasing - optimization issues - multi-core execution issue (works bad with more than 4 core)
sadly ... (
2011/4/16 Michael Snoyman
On Sat, Apr 16, 2011 at 5:54 PM, Chris Casinghino < chris.casinghino@gmail.com> wrote:
On Sat, Apr 16, 2011 at 10:45 AM, Greg Weber
wrote: Are you compiling with the development server or doing a cabal build/
I'm doing a cabal build. To reproduce this, I run (cabal configure && cabal build) from the command line in the project directory.
I can confirm that this happens. However, it *only* happens when building with cabal. When building with "ghc --make", using runghc or wai-handler-devel, everything works fine. So I tried compiling with "ghc --make -O", and sure enough the same bug appeared.
I don't think there's anything we can do in the libraries to avoid this, it looks like a bug in GHC. You can modify your ghc-options line in the cabal file to pass in "-O0" to disable optimizations, though this is obviously not optimal (bad pun intended). I think we need to report this to the GHC team.
I know virtually nothing about GHC internals, but in case this means something to someone else, here's some of the output from "ghc --make -O -v test.hs":
*** Simplify: *** CorePrep: *** ByteCodeGen: *** Desugar: Result size = 8699 *** Simplifier SimplMode {Phase = InitialPhase [Gentle], no inline, rules, eta-expand, no case-of-case} max-iterations=4: Result size = 9841 Result size = 9797 Result size = 9797 *** Specialise: Result size = 9797 *** Float out(FOS {Lam = Just 0, Consts = True, PAPs = False}): Result size = 13259 *** Float inwards: Result size = 13259 *** Simplifier SimplMode {Phase = 2 [main], inline, rules, eta-expand, case-of-case} max-iterations=4: Result size = 677741 Result size = 850762 Result size = 1028928 Result size = 1028928 *** Simplifier SimplMode {Phase = 1 [main], inline, rules, eta-expand, case-of-case} max-iterations=4: Result size = 1026905 Result size = 1026876 Result size = 1026876 *** Simplifier SimplMode {Phase = 0 [main], inline, rules, eta-expand, case-of-case} max-iterations=4:
Michael
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel
-- Best regards, Cheshkov Anton Phone: +7 909 005 18 82 Skype: cheshkov_anton
participants (5)
-
Anton Cheshkov
-
Chris Casinghino
-
Felipe Almeida Lessa
-
Greg Weber
-
Michael Snoyman