Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving inlining by reducing function arity? #370

Open
sjakobi opened this issue Mar 4, 2022 · 1 comment
Open

Improving inlining by reducing function arity? #370

sjakobi opened this issue Mar 4, 2022 · 1 comment

Comments

@sjakobi
Copy link
Member

sjakobi commented Mar 4, 2022

Many functions are currently defined with all their arguments on the LHS, e.g.

lookup :: (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
-- GHC does not yet perform a worker-wrapper transformation on
-- unboxed sums automatically. That seems likely to happen at some
-- point (possibly as early as GHC 8.6) but for now we do it manually.
lookup k m = case lookup# k m of
(# (# #) | #) -> Nothing
(# | a #) -> Just a
{-# INLINE lookup #-}

This means that these functions can only be inlined when they are applied to all their arguments too! For example lookup will not be inlined in this code

foo = lookup k . bar

Therefore it may be useful to reduce the arity of lookup and similar functions at least by one, e.g.

lookup k = \m -> case lookup# k m of …
@sjakobi
Copy link
Member Author

sjakobi commented Mar 4, 2022

See e.g. haskell/bytestring#345 for prior work in bytestring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant