Skip to content

cabal bench should not run benchmarks in parallel #7557

Description

@Bodigrim

When there are several benchmark suites in a package (or - which happens more often - in a project), cabal bench runs them all in parallel, which makes results completely useless. Could cabal run benchmarks sequentially?

Activity

  1. gbaz commented on Aug 18, 2021

    @gbaz
    Collaborator

    I think this would definitely be a welcome improvement.

  2. fgaz commented on Aug 19, 2021

    @fgaz
    Member

    I'm fairly sure benchmark parallelism is handled at the cabal-install level. Cabal only has build parallelism (through GHC)

  3. phadej commented on Aug 19, 2021

    @phadej
    Collaborator

    cabal bench -j1?

  4. Bodigrim commented on Aug 19, 2021

    @Bodigrim
    CollaboratorAuthor

    Not necessarily: I'm still happy for cabal to build benchmarks in parallel.

  5. chreekat commented on Jul 22, 2026

    @chreekat
    Collaborator

    [EDIT: I think I wrote this as a response to #10133, specifically interleaved benchmark output. Oops. Not so relevant here.]

    What kind of solution would be acceptable here?

    I guess cabal-install must already have some machinery for deconflicting parallel activity -- or maybe not?

    I suppose the rough architecture would be

    flowchart LR
    startbuild((start)) --> benches
    subgraph benches ["`benches *(output captured)*`"]
    bench1
    bench2
    bench3
    end
    startbuild --> runningStatus
    runningStatus --> finish((finish))
    bench1 & bench2 & bench3 --> finish
    finish --> summaryResults
    
    Loading
  6. fgaz commented on Jul 22, 2026

    @fgaz
    Member

    We could default cabal bench to -j1. One can always build the benchmarks in parallel with a separate cabal build. However, changing the defaults depending on the command is not great (there's some discussion about this in #5079 and #7883).

    I guess cabal-install must already have some machinery for deconflicting parallel activity -- or maybe not?

    There's Lock. See registerLock for an example.

    Another thing to consider is that parallel builds can also affect benchmark results. For example if bench1 is running while bench2 (or any other component) is building, bench1 might still be affected.

  7. Mikolaj commented on Sep 30, 2026

    @Mikolaj
    Member

    If anybody try tackling this, we'll try to help on the matrix channel. Pretty please!

  8. ulysses4ever commented on Oct 6, 2026

    @ulysses4ever
    Collaborator

    please, consider reviewing a proposed fix for this here:

  9. chreekat commented on Oct 9, 2026

    @chreekat
    Collaborator

    The comment I had meant to write on this thread is that sometimes benchmarks should be run in parallel. All my benchmarks in one project are load-independent; making them serial just wastes cycles. It would be fine with me if the default changed but I'd hope I could still choose to run them in parallel.

  10. Bodigrim commented on Oct 9, 2026

    @Bodigrim
    CollaboratorAuthor

    @chreekat could you elaborate a bit more? I don't quite follow how benchmarks can be load-independent.

  11. phadej commented on Oct 10, 2026

    @phadej
    Collaborator

    I don't quite follow how benchmarks can be load-independent.

    E.g. perf based cpu-cycles / instruction counting ones.

  12. chreekat commented on Oct 10, 2026

    @chreekat
    Collaborator
  13. Bodigrim commented on Oct 10, 2026

    @Bodigrim
    CollaboratorAuthor

    E.g. perf based cpu-cycles counting ones.

    CPU cycles are affected by cache misses and page faults, aren't they? This makes them very much load-dependent.

  14. phadej commented on Oct 10, 2026

    @phadej
    Collaborator

    CPU cycles are affected by cache misses and page faults, aren't they?

    And one can count cache misses and page faults too.

    Or maybe I just want to run benchmarks to see that they work (as part of CI), not actually caring about the output that much.

    The difference between test-suites and benchmarks is very blurry. I'm sure someone could find a reason to run all test-suites in serial too e.g. because they only have only one DB and don't want to write locks inside their tests: something you can do for you benchmarks too.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions