diff options
author | Bartosz Nitka <bnitka@fb.com> | 2017-10-20 20:30:52 +0100 |
---|---|---|
committer | Bartosz Nitka <niteria@gmail.com> | 2017-10-27 15:03:01 -0700 |
commit | faf60e858a293affca463043c830e1edb5685003 (patch) | |
tree | 4b9a0f311780834629bbc8141631cf033db9d11a /compiler/codeGen | |
parent | acd355a8fd40d0446c9f737e0f02d92fb5b7b935 (diff) | |
download | haskell-faf60e858a293affca463043c830e1edb5685003.tar.gz |
Make tagForCon non-linear
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
Diffstat (limited to 'compiler/codeGen')
-rw-r--r-- | compiler/codeGen/StgCmmClosure.hs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/compiler/codeGen/StgCmmClosure.hs b/compiler/codeGen/StgCmmClosure.hs index 1da1f707a2..2501ec9cbd 100644 --- a/compiler/codeGen/StgCmmClosure.hs +++ b/compiler/codeGen/StgCmmClosure.hs @@ -361,13 +361,18 @@ type DynTag = Int -- The tag on a *pointer* isSmallFamily :: DynFlags -> Int -> Bool isSmallFamily dflags fam_size = fam_size <= mAX_PTR_TAG dflags +-- | Faster version of isSmallFamily if you haven't computed the size yet. +isSmallFamilyTyCon :: DynFlags -> TyCon -> Bool +isSmallFamilyTyCon dflags tycon = + tyConFamilySizeAtMost tycon (mAX_PTR_TAG dflags) + tagForCon :: DynFlags -> DataCon -> DynTag tagForCon dflags con - | isSmallFamily dflags fam_size = con_tag - | otherwise = 1 + | isSmallFamilyTyCon dflags tycon = con_tag + | otherwise = 1 where con_tag = dataConTag con -- NB: 1-indexed - fam_size = tyConFamilySize (dataConTyCon con) + tycon = dataConTyCon con tagForArity :: DynFlags -> RepArity -> DynTag tagForArity dflags arity |