Difference between revisions of "Making GHCi scale better and faster"

From HaskellWiki
Jump to navigation Jump to search
m (mark options with <code>)
 
(One intermediate revision by one other user not shown)
Line 5: Line 5:
 
You can do so like so:
 
You can do so like so:
   
<hask>
+
<haskell>
   
 
$ ghci -fobject-code
 
$ ghci -fobject-code
   
</hask>
+
</haskell>
   
 
Or in ghci itself:
 
Or in ghci itself:
   
<hask>
+
<haskell>
   
 
:set -fobject-code
 
:set -fobject-code
   
</hask>
+
</haskell>
   
If you want it on all the time, you can put the above line in a .ghci file either in your home directory or in the directory of your project.
+
If you want it on all the time, you can put the above line in a <code>.ghci</code> file either in your home directory or in the directory of your project.
   
After that, you may notice that loading some modules gives less type information and general metadata than before. For that, re-enable byte-compilation temporarily with -fbyte-code and :load that module again, you now have fast recompilation with complete information, too.
+
After that, you may notice that loading some modules gives less type information and general metadata than before. For that, re-enable byte-compilation temporarily with <code>-fbyte-code</code> and <code>:load</code> that module again, you now have fast recompilation with complete information, too.
   
Another tip is to use -fno-code to have really fast compilation. This also works in combination with -fobject-code. But I’d recommend using this only for type checking, not for getting useful warnings (like pattern match inexhaustiveness). So I would combine it with -fobject-code in the same way as above with -fbyte-code, and then once you’re done hacking, re-enable -fobject-code and rebuild everything.
+
Another tip is to use <code>-fno-code</code> to have really fast compilation. This also works in combination with <code>-fobject-code</code>. But I’d recommend using this only for type checking, not for getting useful warnings (like pattern match inexhaustiveness). So I would combine it with <code>-fobject-code</code> in the same way as above with <code>-fbyte-code</code>, and then once you’re done hacking, re-enable <code>-fobject-code</code> and rebuild everything.

Latest revision as of 18:39, 2 October 2015

A common complaint with GHCi is that it doesn’t scale well when the size of the project gets bigger. Once you hit 20, 30, 50, or 150 modules, it stops being fun anymore and you start wishing you didn’t have to wait for it to load.

I recommend enabling -fobject-code. This makes GHCi compile everything once and then use incremental recompilation thereafter. You’ll find that you can load 100-module projects and work with them just fine in this way.

You can do so like so:

$ ghci -fobject-code

Or in ghci itself:

:set -fobject-code

If you want it on all the time, you can put the above line in a .ghci file either in your home directory or in the directory of your project.

After that, you may notice that loading some modules gives less type information and general metadata than before. For that, re-enable byte-compilation temporarily with -fbyte-code and :load that module again, you now have fast recompilation with complete information, too.

Another tip is to use -fno-code to have really fast compilation. This also works in combination with -fobject-code. But I’d recommend using this only for type checking, not for getting useful warnings (like pattern match inexhaustiveness). So I would combine it with -fobject-code in the same way as above with -fbyte-code, and then once you’re done hacking, re-enable -fobject-code and rebuild everything.