Skip to content

Improve fromList for Data.Map and Data.Set #330

@treeowl

Description

@treeowl

Currently, we try to be very efficient about lists that ascend from the start for most of their length. This seems a tad specific. I suspect what we'd really like to use is an algorithm more like that of Data.List.sort. That is, break up the input into ascending and descending segments, convert each segment, and use union to join the segments together. Unfortunately, the current code is not structured in a way that makes this terribly easy.

Another (less serious) problem is that fromAscListWithKey and fromDescListWithKey preprocess their input lists to squash duplicates. When there aren't any duplicates, this allocates a bunch of short-lived conses. It would be nice to find a way to avoid this, but it's probably not terribly important. I made a brief attempt, but it got horrible pretty quickly.

Another (more serious?) problem is that Data.Map.fromAscList is defined in terms of fromAscListWithKey, which in the lazy case seems rather likely to produce an avoidable space leak. (Fixed in #332)

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