Skip to content

ghcOptExtensionMap can get absurdly big #2110

Closed

Description

@nh2

Hi,

I was just debugging around in hdevtools, printing some stuff (namely this stuff), when I noticed that the ghcOptExtensionMap contains many more entries than I think it should (multiple thousands - we dont' have that many language extensions just yet). The language extensions are repeated (40 times in my case), I believe that's just as many times as I have packages used in this project (ghcOptPackages).

Of course we also do a repeaded linear lookup in this data structure.

Just imagine somebody called nub on this ;)

I think the reason is that GhcOptions are combined with mappend which is implemented as simple list concatenation.

Do I understand it right that we can make this a set, removing the blow up?

Activity

  1. nh2 commented on Sep 17, 2014

    @nh2
    MemberAuthor

    Maybe we could also have a look at whether something like this can happen for other fields.

  2. 23Skidoo commented on Sep 17, 2014

    @23Skidoo
    Member

    Nice catch, but I don't think that Cabal code ever mappends large numbers of GhcOptions records. Basically, the only place GhcOptions.mappend is used is D.S.GHC, and the usage pattern in that file is a mappendmempty {...}mappend mempty {...} ..., so current behaviour of GhcOptions.mappend should be fine.

    In your code, however, I see a line let ghcOpts' = foldl' mappend ..., which is likely what triggered the behaviour you describe.

  3. added 2 commits that reference this issue on Sep 17, 2014
    ccbe2c0
    0fee691
  4. nh2 commented on Sep 17, 2014

    @nh2
    MemberAuthor

    I wanted to say something like "it would be nice if the monoid instance was resistant to people doing things like that", but I see you already patched everything. Nice :)

  5. nh2 commented on Sep 17, 2014

    @nh2
    MemberAuthor

    @23Skidoo Careful though: Like nub, Data.List.union is O(n²).

    Mind using toList . Set.union . fromList?

  6. added a commit that references this issue on Sep 17, 2014
    af176a7
  7. 23Skidoo commented on Sep 17, 2014

    @23Skidoo
    Member

    @nh2 OK, done.

  8. nh2 commented on Sep 17, 2014

    @nh2
    MemberAuthor

    @23Skidoo Perfect. One last thing: Set union is not stable (the output order is defined by the Ord instance instead of the order of occurrence in the two lists). For ghcOptExtensionMap this surely doesn't matter, but I don't know if it does for the other fields.

    It would matter, for example, for ghc options: -Wall -w -Wall has the effect of -Wall (because the last one matters), but if it gets rearranged to -Wall -w, then it has the effect of -w.

    If order-stable equivalents are necessary here, there are some well tested ones on the ordNub page.

  9. added a commit that references this issue on Sep 17, 2014
    05ad067
  10. 23Skidoo commented on Sep 17, 2014

    @23Skidoo
    Member

    Thanks, changed to use your listUnion function.

  11. added a commit that references this issue on Sep 18, 2014
  12. UnkindPartition commented on Sep 25, 2014

    @UnkindPartition
    Contributor

    This is still wrong, I'm afraid.

    Your ordNub is left-biased, if I'm reading it right, and ghc's treatment of extensions is right-biased (which is the most natural, if you think about it).

    For instance, -XOverloadedStrings -XNoOverloadedStrings -XOverloadedStrings is equivalent to -XOverloadedStrings, but cabal will reduce it to -XOverloadedStrings -XNoOverloadedStrings, which is equivalent to -XNoOverloadedStrings.

    A right-biased ordNub should do the job.

  13. nh2 commented on Sep 25, 2014

    @nh2
    MemberAuthor

    You are right; I actually thought I mentioned it but that was somewhere else.

  14. added a commit that references this issue on Sep 26, 2014
    fbd0a7a
  15. 23Skidoo commented on Sep 26, 2014

    @23Skidoo
    Member

    @feuerbach
    Good point. Changed to use right-biased union (e.g. ["-nofoo", "-foo"] union ["-foo", "-nofoo", "-foo"] now produces ["-foo", "-nofoo", "-foo"]).

  16. added 3 commits that reference this issue on Sep 27, 2014
    639fdb5
    967a779
    9318afa
  17. added 2 commits that reference this issue on Oct 19, 2014
    9fbd6bd
    ba4a6d5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions