Skip to content
Snippets Groups Projects

Replace `SizedSeq` with flatten memory representation `FlatBag`

Closed Hannes Siebenhandl requested to merge fendor/ghc:wip/fendor/array-bag into master

LinkedLists are notoriously memory ineffiecient when all we do is traversing a structure. As 'UnlinkedBCO' has been identified as a data structure that impacts the overall memory usage of GHCi sessions, we avoid linked lists and prefer flattened structure for storing.

We introduce a new memory efficient representation of sequential elements, called FlatBag which has special support for the cases:

  • Empty
  • Singleton
  • Tuple Elements

This improves sharing in the 'Empty' case and avoids the overhead of 'SmallArray' until its constant overhead is justified.

FlatBag is supposed to be used when an object is long-lived, rarely written to, and mostly traversed.

Addresses parts of #24539 (closed)

Edited by Hannes Siebenhandl

Merge request reports

Approved by
Test summary results are being parsed

Closed by Marge BotMarge Bot 1 year ago (Apr 4, 2024 6:47pm UTC)

Merge details

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • How big is the perf loss from just using an Array?

    • Resolved by Hannes Siebenhandl

      I think using an empty array would overal take up more memory, as the empty case is not reliably shared over all instances of UnlinkedBCO. Further, on the agda code base, the size distribution of SizedSeq (360_000 * 2 instances of SizedSeq) looks as follows:

            #  length
       283147  0 
       198237  1 
       126478  2 
        69233  3 
        26596  4 
         5587  5 
         3903  6 
         2943  7 

      Thus, we have a special-case for size 0, 1 and 2. Without the special case for size 2, there is only a very little difference in space behaviour.

      Run-time performance-wise, I expect no tangible difference.

      Edited by Hannes Siebenhandl
  • added 1 commit

    • 74822663 - Replace `SizedSeq` with `FlatBag` for flattened structure

    Compare with previous version

  • Hannes Siebenhandl changed title from Replace SizedSeq with {-Array-}Bag for flattened structure to Replace SizedSeq with {+Flat+}Bag for flattened structure

    changed title from Replace SizedSeq with {-Array-}Bag for flattened structure to Replace SizedSeq with {+Flat+}Bag for flattened structure

  • Hannes Siebenhandl changed title from Replace SizedSeq with {-FlatBag for flattened structure-} to Replace SizedSeq with {+flatten memory representation FlatBag+}

    changed title from Replace SizedSeq with {-FlatBag for flattened structure-} to Replace SizedSeq with {+flatten memory representation FlatBag+}

  • mentioned in issue #24539 (closed)

  • Hannes Siebenhandl mentioned in merge request !12140 (closed)

    mentioned in merge request !12140 (closed)

  • Hannes Siebenhandl added 79 commits

    added 79 commits

    Compare with previous version

  • Hannes Siebenhandl resolved all threads

    resolved all threads

  • Hannes Siebenhandl changed the description

    changed the description

  • added 1 commit

    • ac6a01bf - Compact FlatBag array representation

    Compare with previous version

  • Matthew Pickering approved this merge request

    approved this merge request

  • Matthew Pickering assigned to @marge-bot and unassigned @fendor

    assigned to @marge-bot and unassigned @fendor

  • I will attempt to batch this MR (!12365 (closed))...

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading