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

Set NOINLINE pragmas on Generics derived default implementations of Rel8able #346

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.d/20241018_112157_teofilcamarasu_try_noinline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Added

- Add `NOINLINE` pragmas to `Generic` derived default methods of `Rel8able`. This should speed up
compilation times. If users wish for these methods to be `INLINE`d, they can override with a
pragma in their own code.
12 changes: 12 additions & 0 deletions src/Rel8/Generic/Rel8able.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class HTable (GColumns t) => Rel8able t where
type GColumns t = G.GColumns TColumns (GRep t Expr)
type GFromExprs t = t Result

{-# NOINLINE gfromColumns #-} -- See Note [Generics and Inlining]
default gfromColumns :: forall context.
( SRel8able t Expr
, forall table. SRel8able t (Field table)
Expand All @@ -181,6 +182,7 @@ class HTable (GColumns t) => Rel8able t where
SName -> sfromColumns
SResult -> sfromResult

{-# NOINLINE gtoColumns #-} -- See Note [Generics and Inlining]
default gtoColumns :: forall context.
( SRel8able t Expr
, forall table. SRel8able t (Field table)
Expand All @@ -194,10 +196,12 @@ class HTable (GColumns t) => Rel8able t where
SName -> stoColumns
SResult -> stoResult

{-# NOINLINE gfromResult #-} -- See Note [Generics and Inlining]
default gfromResult :: (SSerialize t, GFromExprs t ~ t Result)
=> GColumns t Result -> GFromExprs t
gfromResult = sfromResult

{-# NOINLINE gtoResult #-} -- See Note [Generics and Inlining]
default gtoResult :: (SSerialize t, GFromExprs t ~ t Result)
=> GFromExprs t -> GColumns t Result
gtoResult = stoResult
Expand Down Expand Up @@ -274,3 +278,11 @@ stoResult =
(\(_ :: proxy x) -> serialize @_ @x) .
from .
Record

-- Note [Generics and Inlining]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- We want to make sure that Generics derived functions (by default)
-- do not expose their unfoldings. These are always unoptimised code and can
-- therefore be quite large, and bloat our interfaces.
-- By marking these as NOINLINE we can considerably speed up our compile times.
-- If users do want these INLINEd, they can locally override the default using a pragma.
Loading