Skip to content

Comments

Add --semaphore#6851

Open
horriblename wants to merge 5 commits intocommercialhaskell:masterfrom
horriblename:sema
Open

Add --semaphore#6851
horriblename wants to merge 5 commits intocommercialhaskell:masterfrom
horriblename:sema

Conversation

@horriblename
Copy link

@horriblename horriblename commented Feb 20, 2026

implements #6131

Please include the following checklist in your pull request:

  • Any changes that could be relevant to users have been recorded in ChangeLog.md.
  • The documentation has been updated, if necessary

Please also shortly describe how you tested your change. Bonus points for added tests!

(I'm not sure what kind of test I can add for this?)

a quick benchmark matches claims in https://well-typed.com/blog/2023/08/reducing-haskell-parallel-build-times/ regarding compiling lens (112s vs 140s, ~20% improvement).

$ time stack exec -- stack build --work-dir .temp-work lens
  298.37s user 43.14s system 242% cpu 2:20.69 total

# with --semaphore
$ time stack exec -- stack build --semaphore --work-dir .temp-work lens
  349.93s user 47.79s system 353% cpu 1:52.50 total

rm -r $(stack exec -- stack path --snapshot-pkg-db) was deleted before each run

Some notes about the implementation

  • this uses semaphore-compat, which is also used by cabal

@horriblename horriblename changed the title Sema Add --semaphore Feb 20, 2026
Comment on lines 1149 to 1150
Uses the semaphore feature in Cabal/GHC to build multiple modules from the same
package in parallel. (see GHC's documentation on `-jsem`)
Copy link
Author

Choose a reason for hiding this comment

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

probably better if I can refer to cabal's docs for the --semaphore flag, but I couldn't find any (aside from the extremely short description in --help). There are some docs for cabal-install's --semaphore but that's not quite the same thing

@mpilgrem
Copy link
Member

mpilgrem commented Feb 20, 2026

@horriblename, thanks! Don't worry about the CI for Linux with --alpine (that is waiting for Stack 3.9.3 to appear in Docker images).

I am wondering about the user experience if they accidently specify --semaphore when building with GHC < 9.8.

EDIT: --semaphore appears to have been introduced with Cabal-3.12.0.0, which was a boot package of GHC 9.10.1.

I had not paid attention to --semaphore, as the Cabal project has not yet documented its existence. However, I see that stack runghc -- Setup.hs build --help offers up the (largely unhelpful):

Flags for build:
...
--semaphore=SEMAPHORE          semaphore

I have opened an issue at Cabal's repository:

Also moves `--[no-]semaphore` higher up the list of `stack build --help` options.
@mpilgrem
Copy link
Member

@horriblename, other than handling the Stack user experience when --semaphore=SEMAPHORE is not supported by Cabal, this looks good to me.

I've pushed a commit to better conform the online and in-app documentation to other documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants