Skip to content
  • niteria's avatar
    Make tagForCon non-linear · faf60e85
    niteria authored
    Computing the number of constructors for TyCon is linear
    in the number of constructors.
    That's wasteful if all you want to check is if that
    number is smaller than what fits in tag bits
    (usually 8 things).
    
    What this change does is to use a function that can
    determine the ineqaulity without computing the size.
    
    This improves compile time on a module with a
    data type that has 10k constructors.
    The variance in total time is (suspiciously) high,
    but going by the best of 3 the numbers are 8.186s vs 7.511s.
    For 1000 constructors the difference isn't noticeable:
    0.646s vs 0.624s.
    The hot spots were cgDataCon and cgEnumerationTyCon
    where tagForCon is called in a loop.
    
    One alternative would be to pass down the size.
    
    Test Plan: harbormaster
    
    Reviewers: bgamari, simonmar, austin
    
    Reviewed By: simonmar
    
    Subscribers: rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D4116
    faf60e85