Skip to content

hspec-discover: Prevent GHC from overeagerly simplifying the generated code#958

Open
sol wants to merge 1 commit into
mainfrom
hspec-discover-prevent-simplifying
Open

hspec-discover: Prevent GHC from overeagerly simplifying the generated code#958
sol wants to merge 1 commit into
mainfrom
hspec-discover-prevent-simplifying

Conversation

@sol
Copy link
Copy Markdown
Member

@sol sol commented Mar 6, 2026

No description provided.

Copy link
Copy Markdown

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

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

hell yeah

Comment on lines +51 to +54
, "spec = sequence_ [" ++ unwords [
"describe \"Foo\" FooSpec.spec,"
, "describe \"Foo.Bar\" Foo.BarSpec.spec,"
, "describe \"Foo.Bar.Baz\" Foo.Bar.BazSpec.spec]"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

interestingly enough, I remember having some major compile-time performance boons by switchig code from generating <> chains to using mconcat - I wonder if this is something that is generalizable...

Copy link
Copy Markdown

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

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

I've tested this out on our codebase and ran several builds with the patch. Using our opentelemetry-plugin to get per-module level timing data, unfortunately, the hspec-discover enabled modules did not observe any speedup.

Image

This graph shows builds of our TestGroup modules over the last 7 days. The spike on the far right shows builds now, with the patch enabled. Build times are slightly slower than without the patch. That's pretty surprising, but if you are observing improvements locally, then I wouldn't want to block on this.

One reason why I wouldn't block on this: this is with ghci and we have a heavily patched GHC 9.10.1 so it's entirely possile that we're tripping some regression that we introduced or there's some fix that we don't have incorporated.

@sol
Copy link
Copy Markdown
Member Author

sol commented May 9, 2026

@parsonsmatt sorry, this is not useful to me.

  1. You originally reported build times of ~150s for a top level test driver with 2.6k.
  2. Locally, on my machine, from what I remember, a minimal example with 2.6K imports took even longer than 150s (don't quote me on the exact number, but I think it was around ~180s, maybe even longer).
  3. This PR brings the build time for a test driver with 6k imports (not 2.6k!) down to 7s.

Given this, my expectation is that this PR, applied to your original situation, will bring build times down from 150s to somewhere in the ~2s range.

@parsonsmatt are you willing to try this PR in isolation and confirm (or disproof) my expectation?

Once we properly understand the impact of this PR, we can discuss any further steps (e.g. #954 or -O0).

But please look at this PR in isolation (without #954), because from my experience mashing things together rarely gives you a clear picture of what's actually happening.

this is with ghci

What is with ghci? Your originally reported issue (-150s build times for Spec.hs with 2.6k imports) should never have been an issue with ghci. In ghci "build" (or rather "interpretation") times should always have been close to instant, or at most in the low single digit seconds range. From everything I tried and understand, GHC simply doesn't apply the unfolding that are responsible for #952 in --interactive mode.

@parsonsmatt
Copy link
Copy Markdown

@parsonsmatt are you willing to try this PR in isolation and confirm (or disproof) my expectation?

I've already migrated our codebase over to hspec-discover-discover in tandem with my PR. If I want to revert that, I need to check out a several month old version of our codebase, or undo the migration. In either case, rebuilding our nix shell with a new hspec-discover takes several hours, during which time I cannot do any other computation intensive work. If I revert entirely back to when I initially filed the report, I'll have to rebuild GHC also, which makes it a daylong process to even start building. What you're asking isn't unreasonable, and if the cost weren't so great, I'd gladly do it.

Your own data suggests that your PR is a nice improvement. If I were you, I'd just merge it. We aren't observing any benefit per my prior data. But, that could just come down to our patched GHC version having some different behavior, so our data may not be representative anyway.

The times that I'm looking at are with GHCi. The really long times I reported earlier are from a cabal based build. GHCi is faster, but the modules still take quite some time to load in GHCi. That data is out of our retention window, so I can't bring it up any longer.

@sol sol force-pushed the hspec-discover-prevent-simplifying branch from 49fbf37 to d0eeca7 Compare May 19, 2026 02:52
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