Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

IntSet's minView and maxView creates unwanted thunks

Open
#1,251 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
haskell
Domain
data

Research direction

Start with minView and maxView in containers/src/Data/IntSet/Internal.hs at the linked lines, then compare their definitions with the corresponding IntMap code in containers/src/Data/IntMap/Internal.hs. Generate Core for the affected functions and verify that using the stricter result representation removes the unwanted thunks while preserving the existing IntSet behavior.

Written by the indexing model from the issue text.

Description

IntSet low-hanging-fruit performance

https://github.com/haskell/containers/blob/0c3b9ee93af23f86fb8ad5ffe7729cb82fc4cd3a/containers/src/Data/IntSet/Internal.hs#L1164-L1172

Core:

Rec {
-- RHS size: {terms: 47, types: 28, coercions: 0, joins: 0/1}
$wgo1 [InlPrag=[2], Occ=LoopBreaker] :: IntSet -> (# Int, IntSet #)
[GblId[StrictWorker([!])], Arity=1, Str=<1L>, Unf=OtherCon []]
$wgo1
  = \ (ds_sdOH :: IntSet) ->
      case ds_sdOH of {
        Bin bx_dcyn l_a73T r_a73U ->
          case $wgo1 r_a73U of { (# ww_se6X, ww1_se6Y #) ->
          (# ww_se6X,
             case ww1_se6Y of wild2_X4 {
               __DEFAULT -> Bin bx_dcyn l_a73T wild2_X4;
               Nil -> l_a73T
             } #)
          };
        Tip bx_dcyp bx1_dcyq ->
          let {
            bi_sd64 :: Int#
            [LclId]
            bi_sd64 = -# 63# (word2Int# (clz# bx1_dcyq)) } in
          (# I# (+# bx_dcyp bi_sd64),
             case and# bx1_dcyq (not# (uncheckedShiftL# 1## bi_sd64))
             of ds1_X3 {
               __DEFAULT -> Tip bx_dcyp ds1_X3;
               0## -> Nil
             } #);
        Nil -> case lvl42_reKj of {}
      }

Just using a strict pair instead of lazy should fix it. IntMap's definition seems pretty good and how I would define it for IntSet too, splitting the empty map case out and inlining it to potentially get rid of the Maybe.

https://github.com/haskell/containers/blob/0c3b9ee93af23f86fb8ad5ffe7729cb82fc4cd3a/containers/src/Data/IntMap/Internal.hs#L2325-L2345

Dominant language
Haskell
Stars
356
Forks
196
Avg merge
3d 22h
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from haskell/containers

All issues in haskell/containers

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.