Skip to content

Commit

Permalink
Optimized makefile to speed up compile times of jobs and scripts
Browse files Browse the repository at this point in the history
Previously when compiling a script or job GHC was not reusing any of the previously compiled object files. So for every script and every job a lot of files would be recompiled that might have already been compiled when making the normal server binary. This made production builds much slower than they need to be
  • Loading branch information
mpscholten committed Jul 14, 2021
1 parent 00cf397 commit 1a5411f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/IHP/Makefile.dist
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,13 @@ endif

build/bin/Script/%: build/Script/Main/%.hs
mkdir -p build/bin/Script
ghc -O1 ${GHC_OPTIONS} ${PROD_GHC_OPTIONS} $< -o $@ -odir build/Script -hidir build/Script
# If RunOptimizedProdServer is compiled, likely we have object files with O2 in the build directory, so we're making an optimized script
# Otherwise we're doing a unoptimized compile as it's much faster
if [[ -f "build/bin/RunOptimizedProdServer" ]]; then \
ghc -O2 ${GHC_OPTIONS} ${PROD_GHC_OPTIONS} $< -o $@ -odir build/RunOptimizedProdServer -hidir build/RunOptimizedProdServer; \
else \
ghc -O0 ${GHC_OPTIONS} $< -o $@ -odir build/RunUnoptimizedProdServer -hidir build/RunUnoptimizedProdServer; \
fi

build/Script/Main/%.hs: Application/Script/%.hs
mkdir -p build/Script/Main
Expand All @@ -187,9 +193,15 @@ build/Script/Main/%.hs: Application/Script/%.hs
echo "import Application.Script.$* (run)" >> $@
echo "main = runScript Config.config run" >> $@

build/bin/RunJobs: build/RunJobs.hs
build/bin/RunJobs: build/RunJobs.hs ## Builds an unopimited binary for running the job workers
mkdir -p build/bin
ghc -O0 -main-is 'RunJobs.main' ${GHC_OPTIONS} $< -o $@ -odir build/RunUnoptimizedProdServer -hidir build/RunUnoptimizedProdServer # We use object files by build/bin/RunUnoptimizedProdServer here to speed up compilation during deployments

build/bin/RunJobsOptimized: build/RunJobs.hs ## Builds an optimized binary for running the job workers, symlinks it to build/bin/RunJobs
mkdir -p build/bin
ghc -O1 -main-is 'RunJobs.main' ${GHC_OPTIONS} ${PROD_GHC_OPTIONS} $< -o $@ -odir build -hidir build
ghc -O2 -main-is 'RunJobs.main' ${GHC_OPTIONS} ${PROD_GHC_OPTIONS} $< -o $@ -odir build/RunOptimizedProdServer -hidir build/RunOptimizedProdServer # We use object files by build/bin/RunOptimizedProdServer here to speed up compilation during deployments
rm -f build/bin/RunJobs
ln -s `basename $@` build/bin/RunJobs

build/RunJobs.hs: build/Generated/Types.hs
echo "module RunJobs (main) where" > $@
Expand Down

1 comment on commit 1a5411f

@jyoder
Copy link
Contributor

@jyoder jyoder commented on 1a5411f Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!!

Please sign in to comment.