-
Notifications
You must be signed in to change notification settings - Fork 293
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
Use StandaloneDeriving and DerivingStrategies in persistent-template #1002
Conversation
This PR uses StandaloneDeriving to avoid the handwritten instances that currently exist in persistent-template. In addition, it uses deriving strategies to specify that GeneralizedNewtypeDeriving should be used to derive the instances. This fixes the long-standing issue that derivation would fail if DeriveAnyClass was enabled * Closes #578 * Closes #738 * Closes #908
Master:
Branch:
|
@@ -30,7 +30,6 @@ matrix: | |||
compiler: ": #GHC HEAD" | |||
addons: {apt: {packages: [cabal-install-head,ghc-head,happy-1.19.5,alex-3.1.7], sources: [hvr-ghc]}} | |||
|
|||
- env: BUILD=stack ARGS="--resolver lts-9 --stack-yaml stack_lts-10.yaml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LTS 9 is GHC 8.0
Nothing | ||
constrs | ||
<$> mapM conT names | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer necessary now that we're not supporting GHC 8.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Thanks. I want to test this on the work codebase and see if compile-times increase for our database modules.
, List.intercalate "\n" (map show extensions) | ||
, "\n\nPlease enable the extensions by copy/pasting these lines into the top of your file:\n\n" | ||
, List.intercalate "\n" (map extensionToPragma extensions) | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!! :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad you liked that :)
deriving newtype instance PersistField (BackendKey $(pure backendT)) => PersistField (Key $(pure recordType)) | ||
deriving newtype instance PersistFieldSql (BackendKey $(pure backendT)) => PersistFieldSql (Key $(pure recordType)) | ||
deriving newtype instance ToJSON (BackendKey $(pure backendT)) => ToJSON (Key $(pure recordType)) | ||
deriving newtype instance FromJSON (BackendKey $(pure backendT)) => FromJSON (Key $(pure recordType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yess
Compilation time actually went from ~5:00 to ~4:45 on a full build with this, so hell yeah! I'm a little cautious on that version number though. This is going to be a breaking change for users of the library, and I'm not sure that a patch version bump is appropriate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super excited to get this in and released with the bigger version bump!!
Co-Authored-By: Matt Parsons <parsonsmatt@gmail.com>
Co-Authored-By: Matt Parsons <parsonsmatt@gmail.com>
(NB: this code is based on #1002. Will rebase once that's merged) Currently this function is embedding the full `EntityDef` for every field of the entity. So, for a model with 20 fields, the code to parse a _single field_ embeds the definition of _all 20_ of those fields. This change fixes that. Using the models in persistent-template/test/main.hs as an example, the old generated code to parse _a single field_ looks like this: ``` fromPersistValues [x1_asSh, x2_asSi, x3_asSj, x4_asSk] = Person <$> (Database.Persist.TH.mapLeft ((Database.Persist.TH.fieldError (((((((((((EntityDef (HaskellName (pack "Person"))) (DBName (pack "Person"))) ((((((((FieldDef (HaskellName (pack "Id"))) (DBName (pack "id"))) ((FTTypeCon Nothing) (pack "PersonId"))) SqlInt64) []) True) ((ForeignRef (HaskellName (pack "Person"))) ((FTTypeCon (Just (pack "Data.Int"))) (pack "Int64")))) Nothing)) [pack "json"]) [(((((((FieldDef (HaskellName (pack "name"))) (DBName (pack "name"))) ((FTTypeCon Nothing) (pack "Text"))) SqlString) []) True) NoReference) Nothing, (((((((FieldDef (HaskellName (pack "age"))) (DBName (pack "age"))) ((FTTypeCon Nothing) (pack "Int"))) SqlInt64) [pack "Maybe"]) True) NoReference) Nothing, (((((((FieldDef (HaskellName (pack "foo"))) (DBName (pack "foo"))) ((FTTypeCon Nothing) (pack "Foo"))) SqlString) []) True) NoReference) Nothing, (((((((FieldDef (HaskellName (pack "address"))) (DBName (pack "address"))) ((FTTypeCon Nothing) (pack "Address"))) SqlString) []) True) (EmbedRef ((EmbedEntityDef (HaskellName (pack "Address"))) [((EmbedFieldDef (DBName (pack "street"))) Nothing) Nothing, ((EmbedFieldDef (DBName (pack "city"))) Nothing) Nothing, ((EmbedFieldDef (DBName (pack "zip"))) Nothing) Nothing]))) Nothing]) []) []) [pack "Show", pack "Eq"]) (containers-0.6.0.1:Data.Map.Internal.fromList [])) False) Nothing)) ((((((((FieldDef (HaskellName (pack "name"))) (DBName (pack "name"))) ((FTTypeCon Nothing) (pack "Text"))) SqlString) []) True) NoReference) Nothing)) . fromPersistValue) x1_asSh ``` the new code to parse a single field looks like this: ``` fromPersistValues [x1_asKP, x2_asKQ, x3_asKR, x4_asKS] = Person <$> (Database.Persist.TH.mapLeft ((Database.Persist.TH.fieldError (pack "Person")) (pack "name")) . fromPersistValue) x1_asKP ``` The generated code goes from 2560 to 1848 lines. (The definition of those models for reference) ``` share [mkPersist sqlSettings { mpsGeneric = False }, mkDeleteCascade sqlSettings { mpsGeneric = False }] [persistUpperCase| Person json name Text age Int Maybe foo Foo address Address deriving Show Eq Address json street Text city Text zip Int Maybe deriving Show Eq NoJson foo Text deriving Show Eq |] share [mkPersist sqlSettings { mpsGeneric = False, mpsGenerateLenses = True }] [persistLowerCase| Lperson json name Text age Int Maybe address Laddress deriving Show Eq Laddress json street Text city Text zip Int Maybe deriving Show Eq |] ``` <hr> Benchmarks show a radical improvement. This is master (+ the previous DerivingVia PR): ``` benchmarking mkPersist/From File time 11.75 ms (11.13 ms .. 12.16 ms) 0.982 R² (0.958 R² .. 0.997 R²) mean 12.87 ms (12.49 ms .. 13.67 ms) std dev 1.394 ms (918.6 μs .. 2.229 ms) variance introduced by outliers: 54% (severely inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/1x10 time 18.31 ms (17.98 ms .. 18.71 ms) 0.997 R² (0.994 R² .. 0.999 R²) mean 18.59 ms (18.34 ms .. 18.91 ms) std dev 713.4 μs (526.8 μs .. 955.5 μs) variance introduced by outliers: 13% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/10x10 time 18.21 ms (17.94 ms .. 18.49 ms) 0.999 R² (0.998 R² .. 1.000 R²) mean 18.42 ms (18.26 ms .. 18.68 ms) std dev 485.9 μs (288.8 μs .. 838.4 μs) benchmarking mkPersist/Non-Null Fields/Increasing model count/100x10 time 186.2 ms (159.5 ms .. 211.6 ms) 0.988 R² (0.972 R² .. 1.000 R²) mean 186.3 ms (167.4 ms .. 197.6 ms) std dev 20.57 ms (9.365 ms .. 32.12 ms) variance introduced by outliers: 31% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x1 time 1.101 ms (1.091 ms .. 1.116 ms) 0.999 R² (0.997 R² .. 1.000 R²) mean 1.101 ms (1.093 ms .. 1.114 ms) std dev 34.19 μs (24.45 μs .. 53.26 μs) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x10 time 19.13 ms (18.45 ms .. 19.91 ms) 0.995 R² (0.992 R² .. 0.999 R²) mean 18.09 ms (17.71 ms .. 18.46 ms) std dev 870.8 μs (622.8 μs .. 1.206 ms) variance introduced by outliers: 17% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x100 time 1.140 s (723.1 ms .. 1.522 s) 0.976 R² (0.973 R² .. 1.000 R²) mean 1.093 s (939.5 ms .. 1.197 s) std dev 145.3 ms (8.205 ms .. 181.4 ms) variance introduced by outliers: 24% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/20x10 time 43.58 ms (42.79 ms .. 44.56 ms) 0.998 R² (0.996 R² .. 1.000 R²) mean 43.98 ms (43.34 ms .. 44.86 ms) std dev 1.531 ms (964.5 μs .. 2.408 ms) benchmarking mkPersist/Nullable/Increasing model count/40x10 time 89.01 ms (85.38 ms .. 91.83 ms) 0.997 R² (0.993 R² .. 0.999 R²) mean 87.92 ms (81.29 ms .. 91.09 ms) std dev 7.472 ms (3.033 ms .. 12.94 ms) variance introduced by outliers: 28% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/60x10 time 116.4 ms (105.6 ms .. 123.7 ms) 0.994 R² (0.986 R² .. 0.999 R²) mean 126.8 ms (121.4 ms .. 133.0 ms) std dev 8.540 ms (5.824 ms .. 11.83 ms) variance introduced by outliers: 12% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/80x10 time 197.2 ms (164.6 ms .. 232.6 ms) 0.988 R² (0.958 R² .. 1.000 R²) mean 189.6 ms (176.6 ms .. 201.4 ms) std dev 17.32 ms (9.377 ms .. 25.86 ms) variance introduced by outliers: 16% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/100x10 time 262.8 ms (225.6 ms .. 281.7 ms) 0.990 R² (0.970 R² .. 1.000 R²) mean 248.4 ms (234.2 ms .. 258.1 ms) std dev 15.63 ms (10.30 ms .. 19.52 ms) variance introduced by outliers: 17% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x20 time 90.77 ms (81.84 ms .. 101.5 ms) 0.974 R² (0.932 R² .. 0.997 R²) mean 73.75 ms (66.31 ms .. 80.22 ms) std dev 11.92 ms (8.285 ms .. 18.59 ms) variance introduced by outliers: 58% (severely inflated) benchmarking mkPersist/Nullable/Increasing field count/10x40 time 258.2 ms (202.5 ms .. 316.8 ms) 0.988 R² (0.968 R² .. 1.000 R²) mean 235.6 ms (193.4 ms .. 253.5 ms) std dev 33.43 ms (10.60 ms .. 49.19 ms) variance introduced by outliers: 38% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x60 time 542.3 ms (431.4 ms .. 591.7 ms) 0.995 R² (0.988 R² .. 1.000 R²) mean 528.9 ms (499.9 ms .. 545.4 ms) std dev 28.15 ms (9.013 ms .. 37.98 ms) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x80 time 908.0 ms (814.3 ms .. 1.091 s) 0.995 R² (0.990 R² .. 1.000 R²) mean 838.9 ms (751.9 ms .. 886.1 ms) std dev 85.02 ms (3.280 ms .. 108.9 ms) variance introduced by outliers: 23% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x100 time 1.621 s (1.129 s .. 1.879 s) 0.990 R² (0.970 R² .. 1.000 R²) mean 1.405 s (1.197 s .. 1.523 s) std dev 202.9 ms (57.30 ms .. 273.0 ms) variance introduced by outliers: 24% (moderately inflated) ``` vs this branch: ``` benchmarking mkPersist/From File time 621.8 μs (612.2 μs .. 633.9 μs) 0.996 R² (0.994 R² .. 0.998 R²) mean 668.6 μs (656.5 μs .. 683.9 μs) std dev 46.55 μs (37.19 μs .. 67.34 μs) variance introduced by outliers: 59% (severely inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/1x10 time 4.577 ms (4.409 ms .. 4.833 ms) 0.983 R² (0.965 R² .. 0.996 R²) mean 4.610 ms (4.512 ms .. 4.726 ms) std dev 324.7 μs (239.5 μs .. 460.0 μs) variance introduced by outliers: 44% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/10x10 time 4.479 ms (4.348 ms .. 4.628 ms) 0.994 R² (0.991 R² .. 0.997 R²) mean 4.717 ms (4.647 ms .. 4.768 ms) std dev 188.8 μs (143.7 μs .. 235.5 μs) variance introduced by outliers: 20% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/100x10 time 55.67 ms (53.85 ms .. 57.68 ms) 0.995 R² (0.986 R² .. 0.999 R²) mean 55.03 ms (51.81 ms .. 56.67 ms) std dev 4.023 ms (2.152 ms .. 6.421 ms) variance introduced by outliers: 23% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x1 time 885.4 μs (873.7 μs .. 898.4 μs) 0.998 R² (0.997 R² .. 0.999 R²) mean 909.3 μs (899.6 μs .. 923.9 μs) std dev 40.42 μs (29.71 μs .. 61.27 μs) variance introduced by outliers: 36% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x10 time 4.669 ms (4.463 ms .. 4.850 ms) 0.991 R² (0.985 R² .. 0.995 R²) mean 4.673 ms (4.590 ms .. 4.754 ms) std dev 264.4 μs (226.1 μs .. 318.1 μs) variance introduced by outliers: 34% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x100 time 43.01 ms (41.66 ms .. 44.14 ms) 0.997 R² (0.992 R² .. 0.999 R²) mean 42.88 ms (40.65 ms .. 44.22 ms) std dev 3.305 ms (1.574 ms .. 5.780 ms) variance introduced by outliers: 27% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/20x10 time 11.38 ms (11.18 ms .. 11.68 ms) 0.995 R² (0.985 R² .. 0.999 R²) mean 11.16 ms (10.97 ms .. 11.41 ms) std dev 603.2 μs (391.3 μs .. 912.9 μs) variance introduced by outliers: 26% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/40x10 time 24.00 ms (23.56 ms .. 24.38 ms) 0.999 R² (0.997 R² .. 0.999 R²) mean 23.97 ms (23.74 ms .. 24.24 ms) std dev 538.8 μs (409.6 μs .. 720.3 μs) benchmarking mkPersist/Nullable/Increasing model count/60x10 time 39.98 ms (37.68 ms .. 43.16 ms) 0.988 R² (0.976 R² .. 0.999 R²) mean 36.94 ms (36.04 ms .. 38.32 ms) std dev 2.173 ms (1.135 ms .. 3.656 ms) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/80x10 time 51.12 ms (44.79 ms .. 57.38 ms) 0.969 R² (0.915 R² .. 0.998 R²) mean 56.90 ms (53.41 ms .. 60.70 ms) std dev 6.589 ms (4.712 ms .. 8.849 ms) variance introduced by outliers: 40% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/100x10 time 60.83 ms (55.87 ms .. 65.23 ms) 0.991 R² (0.983 R² .. 0.999 R²) mean 63.33 ms (59.62 ms .. 65.63 ms) std dev 5.272 ms (2.846 ms .. 8.609 ms) variance introduced by outliers: 24% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x20 time 9.925 ms (9.701 ms .. 10.16 ms) 0.995 R² (0.991 R² .. 0.998 R²) mean 10.15 ms (9.972 ms .. 10.31 ms) std dev 460.9 μs (371.1 μs .. 571.1 μs) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x40 time 19.03 ms (18.30 ms .. 19.67 ms) 0.994 R² (0.988 R² .. 0.997 R²) mean 20.77 ms (19.98 ms .. 22.18 ms) std dev 2.346 ms (1.350 ms .. 3.393 ms) variance introduced by outliers: 51% (severely inflated) benchmarking mkPersist/Nullable/Increasing field count/10x60 time 29.54 ms (28.63 ms .. 30.63 ms) 0.996 R² (0.993 R² .. 0.998 R²) mean 29.85 ms (29.35 ms .. 30.35 ms) std dev 1.064 ms (835.8 μs .. 1.455 ms) variance introduced by outliers: 11% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x80 time 39.68 ms (38.06 ms .. 41.69 ms) 0.993 R² (0.985 R² .. 0.998 R²) mean 39.61 ms (37.67 ms .. 40.74 ms) std dev 3.070 ms (1.579 ms .. 5.208 ms) variance introduced by outliers: 25% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x100 time 48.92 ms (46.41 ms .. 50.57 ms) 0.996 R² (0.993 R² .. 0.998 R²) mean 49.09 ms (46.21 ms .. 50.95 ms) std dev 4.472 ms (2.372 ms .. 8.241 ms) variance introduced by outliers: 29% (moderately inflated) ```
The upcoming version of persistent-template will require these yesodweb/persistent#1002
…t persistent-template The upcoming version of persistent-template will require these yesodweb/persistent#1002
* persistent-tempalte: Use StandaloneDeriving and DerivingStrategies This PR uses StandaloneDeriving to avoid the handwritten instances that currently exist in persistent-template. In addition, it uses deriving strategies to specify that GeneralizedNewtypeDeriving should be used to derive the instances. This fixes the long-standing issue that derivation would fail if DeriveAnyClass was enabled * Closes #578 * Closes #738 * Closes #908 * .. * .. * .. * .. * .. * .. * test fixes * test fixes * .. * Update persistent-template/ChangeLog.md Co-Authored-By: Matt Parsons <parsonsmatt@gmail.com> * Update persistent-template/persistent-template.cabal Co-Authored-By: Matt Parsons <parsonsmatt@gmail.com> * Reduce code generated by fromPersistValues (NB: this code is based on #1002. Will rebase once that's merged) Currently this function is embedding the full `EntityDef` for every field of the entity. So, for a model with 20 fields, the code to parse a _single field_ embeds the definition of _all 20_ of those fields. This change fixes that. Using the models in persistent-template/test/main.hs as an example, the old generated code to parse _a single field_ looks like this: ``` fromPersistValues [x1_asSh, x2_asSi, x3_asSj, x4_asSk] = Person <$> (Database.Persist.TH.mapLeft ((Database.Persist.TH.fieldError (((((((((((EntityDef (HaskellName (pack "Person"))) (DBName (pack "Person"))) ((((((((FieldDef (HaskellName (pack "Id"))) (DBName (pack "id"))) ((FTTypeCon Nothing) (pack "PersonId"))) SqlInt64) []) True) ((ForeignRef (HaskellName (pack "Person"))) ((FTTypeCon (Just (pack "Data.Int"))) (pack "Int64")))) Nothing)) [pack "json"]) [(((((((FieldDef (HaskellName (pack "name"))) (DBName (pack "name"))) ((FTTypeCon Nothing) (pack "Text"))) SqlString) []) True) NoReference) Nothing, (((((((FieldDef (HaskellName (pack "age"))) (DBName (pack "age"))) ((FTTypeCon Nothing) (pack "Int"))) SqlInt64) [pack "Maybe"]) True) NoReference) Nothing, (((((((FieldDef (HaskellName (pack "foo"))) (DBName (pack "foo"))) ((FTTypeCon Nothing) (pack "Foo"))) SqlString) []) True) NoReference) Nothing, (((((((FieldDef (HaskellName (pack "address"))) (DBName (pack "address"))) ((FTTypeCon Nothing) (pack "Address"))) SqlString) []) True) (EmbedRef ((EmbedEntityDef (HaskellName (pack "Address"))) [((EmbedFieldDef (DBName (pack "street"))) Nothing) Nothing, ((EmbedFieldDef (DBName (pack "city"))) Nothing) Nothing, ((EmbedFieldDef (DBName (pack "zip"))) Nothing) Nothing]))) Nothing]) []) []) [pack "Show", pack "Eq"]) (containers-0.6.0.1:Data.Map.Internal.fromList [])) False) Nothing)) ((((((((FieldDef (HaskellName (pack "name"))) (DBName (pack "name"))) ((FTTypeCon Nothing) (pack "Text"))) SqlString) []) True) NoReference) Nothing)) . fromPersistValue) x1_asSh ``` the new code to parse a single field looks like this: ``` fromPersistValues [x1_asKP, x2_asKQ, x3_asKR, x4_asKS] = Person <$> (Database.Persist.TH.mapLeft ((Database.Persist.TH.fieldError (pack "Person")) (pack "name")) . fromPersistValue) x1_asKP ``` The generated code goes from 2560 to 1848 lines. (The definition of those models for reference) ``` share [mkPersist sqlSettings { mpsGeneric = False }, mkDeleteCascade sqlSettings { mpsGeneric = False }] [persistUpperCase| Person json name Text age Int Maybe foo Foo address Address deriving Show Eq Address json street Text city Text zip Int Maybe deriving Show Eq NoJson foo Text deriving Show Eq |] share [mkPersist sqlSettings { mpsGeneric = False, mpsGenerateLenses = True }] [persistLowerCase| Lperson json name Text age Int Maybe address Laddress deriving Show Eq Laddress json street Text city Text zip Int Maybe deriving Show Eq |] ``` <hr> Benchmarks show a radical improvement. This is master (+ the previous DerivingVia PR): ``` benchmarking mkPersist/From File time 11.75 ms (11.13 ms .. 12.16 ms) 0.982 R² (0.958 R² .. 0.997 R²) mean 12.87 ms (12.49 ms .. 13.67 ms) std dev 1.394 ms (918.6 μs .. 2.229 ms) variance introduced by outliers: 54% (severely inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/1x10 time 18.31 ms (17.98 ms .. 18.71 ms) 0.997 R² (0.994 R² .. 0.999 R²) mean 18.59 ms (18.34 ms .. 18.91 ms) std dev 713.4 μs (526.8 μs .. 955.5 μs) variance introduced by outliers: 13% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/10x10 time 18.21 ms (17.94 ms .. 18.49 ms) 0.999 R² (0.998 R² .. 1.000 R²) mean 18.42 ms (18.26 ms .. 18.68 ms) std dev 485.9 μs (288.8 μs .. 838.4 μs) benchmarking mkPersist/Non-Null Fields/Increasing model count/100x10 time 186.2 ms (159.5 ms .. 211.6 ms) 0.988 R² (0.972 R² .. 1.000 R²) mean 186.3 ms (167.4 ms .. 197.6 ms) std dev 20.57 ms (9.365 ms .. 32.12 ms) variance introduced by outliers: 31% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x1 time 1.101 ms (1.091 ms .. 1.116 ms) 0.999 R² (0.997 R² .. 1.000 R²) mean 1.101 ms (1.093 ms .. 1.114 ms) std dev 34.19 μs (24.45 μs .. 53.26 μs) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x10 time 19.13 ms (18.45 ms .. 19.91 ms) 0.995 R² (0.992 R² .. 0.999 R²) mean 18.09 ms (17.71 ms .. 18.46 ms) std dev 870.8 μs (622.8 μs .. 1.206 ms) variance introduced by outliers: 17% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x100 time 1.140 s (723.1 ms .. 1.522 s) 0.976 R² (0.973 R² .. 1.000 R²) mean 1.093 s (939.5 ms .. 1.197 s) std dev 145.3 ms (8.205 ms .. 181.4 ms) variance introduced by outliers: 24% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/20x10 time 43.58 ms (42.79 ms .. 44.56 ms) 0.998 R² (0.996 R² .. 1.000 R²) mean 43.98 ms (43.34 ms .. 44.86 ms) std dev 1.531 ms (964.5 μs .. 2.408 ms) benchmarking mkPersist/Nullable/Increasing model count/40x10 time 89.01 ms (85.38 ms .. 91.83 ms) 0.997 R² (0.993 R² .. 0.999 R²) mean 87.92 ms (81.29 ms .. 91.09 ms) std dev 7.472 ms (3.033 ms .. 12.94 ms) variance introduced by outliers: 28% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/60x10 time 116.4 ms (105.6 ms .. 123.7 ms) 0.994 R² (0.986 R² .. 0.999 R²) mean 126.8 ms (121.4 ms .. 133.0 ms) std dev 8.540 ms (5.824 ms .. 11.83 ms) variance introduced by outliers: 12% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/80x10 time 197.2 ms (164.6 ms .. 232.6 ms) 0.988 R² (0.958 R² .. 1.000 R²) mean 189.6 ms (176.6 ms .. 201.4 ms) std dev 17.32 ms (9.377 ms .. 25.86 ms) variance introduced by outliers: 16% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/100x10 time 262.8 ms (225.6 ms .. 281.7 ms) 0.990 R² (0.970 R² .. 1.000 R²) mean 248.4 ms (234.2 ms .. 258.1 ms) std dev 15.63 ms (10.30 ms .. 19.52 ms) variance introduced by outliers: 17% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x20 time 90.77 ms (81.84 ms .. 101.5 ms) 0.974 R² (0.932 R² .. 0.997 R²) mean 73.75 ms (66.31 ms .. 80.22 ms) std dev 11.92 ms (8.285 ms .. 18.59 ms) variance introduced by outliers: 58% (severely inflated) benchmarking mkPersist/Nullable/Increasing field count/10x40 time 258.2 ms (202.5 ms .. 316.8 ms) 0.988 R² (0.968 R² .. 1.000 R²) mean 235.6 ms (193.4 ms .. 253.5 ms) std dev 33.43 ms (10.60 ms .. 49.19 ms) variance introduced by outliers: 38% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x60 time 542.3 ms (431.4 ms .. 591.7 ms) 0.995 R² (0.988 R² .. 1.000 R²) mean 528.9 ms (499.9 ms .. 545.4 ms) std dev 28.15 ms (9.013 ms .. 37.98 ms) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x80 time 908.0 ms (814.3 ms .. 1.091 s) 0.995 R² (0.990 R² .. 1.000 R²) mean 838.9 ms (751.9 ms .. 886.1 ms) std dev 85.02 ms (3.280 ms .. 108.9 ms) variance introduced by outliers: 23% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x100 time 1.621 s (1.129 s .. 1.879 s) 0.990 R² (0.970 R² .. 1.000 R²) mean 1.405 s (1.197 s .. 1.523 s) std dev 202.9 ms (57.30 ms .. 273.0 ms) variance introduced by outliers: 24% (moderately inflated) ``` vs this branch: ``` benchmarking mkPersist/From File time 621.8 μs (612.2 μs .. 633.9 μs) 0.996 R² (0.994 R² .. 0.998 R²) mean 668.6 μs (656.5 μs .. 683.9 μs) std dev 46.55 μs (37.19 μs .. 67.34 μs) variance introduced by outliers: 59% (severely inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/1x10 time 4.577 ms (4.409 ms .. 4.833 ms) 0.983 R² (0.965 R² .. 0.996 R²) mean 4.610 ms (4.512 ms .. 4.726 ms) std dev 324.7 μs (239.5 μs .. 460.0 μs) variance introduced by outliers: 44% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/10x10 time 4.479 ms (4.348 ms .. 4.628 ms) 0.994 R² (0.991 R² .. 0.997 R²) mean 4.717 ms (4.647 ms .. 4.768 ms) std dev 188.8 μs (143.7 μs .. 235.5 μs) variance introduced by outliers: 20% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/100x10 time 55.67 ms (53.85 ms .. 57.68 ms) 0.995 R² (0.986 R² .. 0.999 R²) mean 55.03 ms (51.81 ms .. 56.67 ms) std dev 4.023 ms (2.152 ms .. 6.421 ms) variance introduced by outliers: 23% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x1 time 885.4 μs (873.7 μs .. 898.4 μs) 0.998 R² (0.997 R² .. 0.999 R²) mean 909.3 μs (899.6 μs .. 923.9 μs) std dev 40.42 μs (29.71 μs .. 61.27 μs) variance introduced by outliers: 36% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x10 time 4.669 ms (4.463 ms .. 4.850 ms) 0.991 R² (0.985 R² .. 0.995 R²) mean 4.673 ms (4.590 ms .. 4.754 ms) std dev 264.4 μs (226.1 μs .. 318.1 μs) variance introduced by outliers: 34% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x100 time 43.01 ms (41.66 ms .. 44.14 ms) 0.997 R² (0.992 R² .. 0.999 R²) mean 42.88 ms (40.65 ms .. 44.22 ms) std dev 3.305 ms (1.574 ms .. 5.780 ms) variance introduced by outliers: 27% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/20x10 time 11.38 ms (11.18 ms .. 11.68 ms) 0.995 R² (0.985 R² .. 0.999 R²) mean 11.16 ms (10.97 ms .. 11.41 ms) std dev 603.2 μs (391.3 μs .. 912.9 μs) variance introduced by outliers: 26% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/40x10 time 24.00 ms (23.56 ms .. 24.38 ms) 0.999 R² (0.997 R² .. 0.999 R²) mean 23.97 ms (23.74 ms .. 24.24 ms) std dev 538.8 μs (409.6 μs .. 720.3 μs) benchmarking mkPersist/Nullable/Increasing model count/60x10 time 39.98 ms (37.68 ms .. 43.16 ms) 0.988 R² (0.976 R² .. 0.999 R²) mean 36.94 ms (36.04 ms .. 38.32 ms) std dev 2.173 ms (1.135 ms .. 3.656 ms) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/80x10 time 51.12 ms (44.79 ms .. 57.38 ms) 0.969 R² (0.915 R² .. 0.998 R²) mean 56.90 ms (53.41 ms .. 60.70 ms) std dev 6.589 ms (4.712 ms .. 8.849 ms) variance introduced by outliers: 40% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/100x10 time 60.83 ms (55.87 ms .. 65.23 ms) 0.991 R² (0.983 R² .. 0.999 R²) mean 63.33 ms (59.62 ms .. 65.63 ms) std dev 5.272 ms (2.846 ms .. 8.609 ms) variance introduced by outliers: 24% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x20 time 9.925 ms (9.701 ms .. 10.16 ms) 0.995 R² (0.991 R² .. 0.998 R²) mean 10.15 ms (9.972 ms .. 10.31 ms) std dev 460.9 μs (371.1 μs .. 571.1 μs) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x40 time 19.03 ms (18.30 ms .. 19.67 ms) 0.994 R² (0.988 R² .. 0.997 R²) mean 20.77 ms (19.98 ms .. 22.18 ms) std dev 2.346 ms (1.350 ms .. 3.393 ms) variance introduced by outliers: 51% (severely inflated) benchmarking mkPersist/Nullable/Increasing field count/10x60 time 29.54 ms (28.63 ms .. 30.63 ms) 0.996 R² (0.993 R² .. 0.998 R²) mean 29.85 ms (29.35 ms .. 30.35 ms) std dev 1.064 ms (835.8 μs .. 1.455 ms) variance introduced by outliers: 11% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x80 time 39.68 ms (38.06 ms .. 41.69 ms) 0.993 R² (0.985 R² .. 0.998 R²) mean 39.61 ms (37.67 ms .. 40.74 ms) std dev 3.070 ms (1.579 ms .. 5.208 ms) variance introduced by outliers: 25% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x100 time 48.92 ms (46.41 ms .. 50.57 ms) 0.996 R² (0.993 R² .. 0.998 R²) mean 49.09 ms (46.21 ms .. 50.95 ms) std dev 4.472 ms (2.372 ms .. 8.241 ms) variance introduced by outliers: 29% (moderately inflated) ``` Co-authored-by: Matt Parsons <parsonsmatt@gmail.com>
* persistent-tempalte: Use StandaloneDeriving and DerivingStrategies This PR uses StandaloneDeriving to avoid the handwritten instances that currently exist in persistent-template. In addition, it uses deriving strategies to specify that GeneralizedNewtypeDeriving should be used to derive the instances. This fixes the long-standing issue that derivation would fail if DeriveAnyClass was enabled * Closes yesodweb#578 * Closes yesodweb#738 * Closes yesodweb#908 * .. * .. * .. * .. * .. * .. * test fixes * test fixes * .. * Update persistent-template/ChangeLog.md Co-Authored-By: Matt Parsons <parsonsmatt@gmail.com> * Update persistent-template/persistent-template.cabal Co-Authored-By: Matt Parsons <parsonsmatt@gmail.com> * Reduce code generated by fromPersistValues (NB: this code is based on yesodweb#1002. Will rebase once that's merged) Currently this function is embedding the full `EntityDef` for every field of the entity. So, for a model with 20 fields, the code to parse a _single field_ embeds the definition of _all 20_ of those fields. This change fixes that. Using the models in persistent-template/test/main.hs as an example, the old generated code to parse _a single field_ looks like this: ``` fromPersistValues [x1_asSh, x2_asSi, x3_asSj, x4_asSk] = Person <$> (Database.Persist.TH.mapLeft ((Database.Persist.TH.fieldError (((((((((((EntityDef (HaskellName (pack "Person"))) (DBName (pack "Person"))) ((((((((FieldDef (HaskellName (pack "Id"))) (DBName (pack "id"))) ((FTTypeCon Nothing) (pack "PersonId"))) SqlInt64) []) True) ((ForeignRef (HaskellName (pack "Person"))) ((FTTypeCon (Just (pack "Data.Int"))) (pack "Int64")))) Nothing)) [pack "json"]) [(((((((FieldDef (HaskellName (pack "name"))) (DBName (pack "name"))) ((FTTypeCon Nothing) (pack "Text"))) SqlString) []) True) NoReference) Nothing, (((((((FieldDef (HaskellName (pack "age"))) (DBName (pack "age"))) ((FTTypeCon Nothing) (pack "Int"))) SqlInt64) [pack "Maybe"]) True) NoReference) Nothing, (((((((FieldDef (HaskellName (pack "foo"))) (DBName (pack "foo"))) ((FTTypeCon Nothing) (pack "Foo"))) SqlString) []) True) NoReference) Nothing, (((((((FieldDef (HaskellName (pack "address"))) (DBName (pack "address"))) ((FTTypeCon Nothing) (pack "Address"))) SqlString) []) True) (EmbedRef ((EmbedEntityDef (HaskellName (pack "Address"))) [((EmbedFieldDef (DBName (pack "street"))) Nothing) Nothing, ((EmbedFieldDef (DBName (pack "city"))) Nothing) Nothing, ((EmbedFieldDef (DBName (pack "zip"))) Nothing) Nothing]))) Nothing]) []) []) [pack "Show", pack "Eq"]) (containers-0.6.0.1:Data.Map.Internal.fromList [])) False) Nothing)) ((((((((FieldDef (HaskellName (pack "name"))) (DBName (pack "name"))) ((FTTypeCon Nothing) (pack "Text"))) SqlString) []) True) NoReference) Nothing)) . fromPersistValue) x1_asSh ``` the new code to parse a single field looks like this: ``` fromPersistValues [x1_asKP, x2_asKQ, x3_asKR, x4_asKS] = Person <$> (Database.Persist.TH.mapLeft ((Database.Persist.TH.fieldError (pack "Person")) (pack "name")) . fromPersistValue) x1_asKP ``` The generated code goes from 2560 to 1848 lines. (The definition of those models for reference) ``` share [mkPersist sqlSettings { mpsGeneric = False }, mkDeleteCascade sqlSettings { mpsGeneric = False }] [persistUpperCase| Person json name Text age Int Maybe foo Foo address Address deriving Show Eq Address json street Text city Text zip Int Maybe deriving Show Eq NoJson foo Text deriving Show Eq |] share [mkPersist sqlSettings { mpsGeneric = False, mpsGenerateLenses = True }] [persistLowerCase| Lperson json name Text age Int Maybe address Laddress deriving Show Eq Laddress json street Text city Text zip Int Maybe deriving Show Eq |] ``` <hr> Benchmarks show a radical improvement. This is master (+ the previous DerivingVia PR): ``` benchmarking mkPersist/From File time 11.75 ms (11.13 ms .. 12.16 ms) 0.982 R² (0.958 R² .. 0.997 R²) mean 12.87 ms (12.49 ms .. 13.67 ms) std dev 1.394 ms (918.6 μs .. 2.229 ms) variance introduced by outliers: 54% (severely inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/1x10 time 18.31 ms (17.98 ms .. 18.71 ms) 0.997 R² (0.994 R² .. 0.999 R²) mean 18.59 ms (18.34 ms .. 18.91 ms) std dev 713.4 μs (526.8 μs .. 955.5 μs) variance introduced by outliers: 13% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/10x10 time 18.21 ms (17.94 ms .. 18.49 ms) 0.999 R² (0.998 R² .. 1.000 R²) mean 18.42 ms (18.26 ms .. 18.68 ms) std dev 485.9 μs (288.8 μs .. 838.4 μs) benchmarking mkPersist/Non-Null Fields/Increasing model count/100x10 time 186.2 ms (159.5 ms .. 211.6 ms) 0.988 R² (0.972 R² .. 1.000 R²) mean 186.3 ms (167.4 ms .. 197.6 ms) std dev 20.57 ms (9.365 ms .. 32.12 ms) variance introduced by outliers: 31% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x1 time 1.101 ms (1.091 ms .. 1.116 ms) 0.999 R² (0.997 R² .. 1.000 R²) mean 1.101 ms (1.093 ms .. 1.114 ms) std dev 34.19 μs (24.45 μs .. 53.26 μs) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x10 time 19.13 ms (18.45 ms .. 19.91 ms) 0.995 R² (0.992 R² .. 0.999 R²) mean 18.09 ms (17.71 ms .. 18.46 ms) std dev 870.8 μs (622.8 μs .. 1.206 ms) variance introduced by outliers: 17% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x100 time 1.140 s (723.1 ms .. 1.522 s) 0.976 R² (0.973 R² .. 1.000 R²) mean 1.093 s (939.5 ms .. 1.197 s) std dev 145.3 ms (8.205 ms .. 181.4 ms) variance introduced by outliers: 24% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/20x10 time 43.58 ms (42.79 ms .. 44.56 ms) 0.998 R² (0.996 R² .. 1.000 R²) mean 43.98 ms (43.34 ms .. 44.86 ms) std dev 1.531 ms (964.5 μs .. 2.408 ms) benchmarking mkPersist/Nullable/Increasing model count/40x10 time 89.01 ms (85.38 ms .. 91.83 ms) 0.997 R² (0.993 R² .. 0.999 R²) mean 87.92 ms (81.29 ms .. 91.09 ms) std dev 7.472 ms (3.033 ms .. 12.94 ms) variance introduced by outliers: 28% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/60x10 time 116.4 ms (105.6 ms .. 123.7 ms) 0.994 R² (0.986 R² .. 0.999 R²) mean 126.8 ms (121.4 ms .. 133.0 ms) std dev 8.540 ms (5.824 ms .. 11.83 ms) variance introduced by outliers: 12% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/80x10 time 197.2 ms (164.6 ms .. 232.6 ms) 0.988 R² (0.958 R² .. 1.000 R²) mean 189.6 ms (176.6 ms .. 201.4 ms) std dev 17.32 ms (9.377 ms .. 25.86 ms) variance introduced by outliers: 16% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/100x10 time 262.8 ms (225.6 ms .. 281.7 ms) 0.990 R² (0.970 R² .. 1.000 R²) mean 248.4 ms (234.2 ms .. 258.1 ms) std dev 15.63 ms (10.30 ms .. 19.52 ms) variance introduced by outliers: 17% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x20 time 90.77 ms (81.84 ms .. 101.5 ms) 0.974 R² (0.932 R² .. 0.997 R²) mean 73.75 ms (66.31 ms .. 80.22 ms) std dev 11.92 ms (8.285 ms .. 18.59 ms) variance introduced by outliers: 58% (severely inflated) benchmarking mkPersist/Nullable/Increasing field count/10x40 time 258.2 ms (202.5 ms .. 316.8 ms) 0.988 R² (0.968 R² .. 1.000 R²) mean 235.6 ms (193.4 ms .. 253.5 ms) std dev 33.43 ms (10.60 ms .. 49.19 ms) variance introduced by outliers: 38% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x60 time 542.3 ms (431.4 ms .. 591.7 ms) 0.995 R² (0.988 R² .. 1.000 R²) mean 528.9 ms (499.9 ms .. 545.4 ms) std dev 28.15 ms (9.013 ms .. 37.98 ms) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x80 time 908.0 ms (814.3 ms .. 1.091 s) 0.995 R² (0.990 R² .. 1.000 R²) mean 838.9 ms (751.9 ms .. 886.1 ms) std dev 85.02 ms (3.280 ms .. 108.9 ms) variance introduced by outliers: 23% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x100 time 1.621 s (1.129 s .. 1.879 s) 0.990 R² (0.970 R² .. 1.000 R²) mean 1.405 s (1.197 s .. 1.523 s) std dev 202.9 ms (57.30 ms .. 273.0 ms) variance introduced by outliers: 24% (moderately inflated) ``` vs this branch: ``` benchmarking mkPersist/From File time 621.8 μs (612.2 μs .. 633.9 μs) 0.996 R² (0.994 R² .. 0.998 R²) mean 668.6 μs (656.5 μs .. 683.9 μs) std dev 46.55 μs (37.19 μs .. 67.34 μs) variance introduced by outliers: 59% (severely inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/1x10 time 4.577 ms (4.409 ms .. 4.833 ms) 0.983 R² (0.965 R² .. 0.996 R²) mean 4.610 ms (4.512 ms .. 4.726 ms) std dev 324.7 μs (239.5 μs .. 460.0 μs) variance introduced by outliers: 44% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/10x10 time 4.479 ms (4.348 ms .. 4.628 ms) 0.994 R² (0.991 R² .. 0.997 R²) mean 4.717 ms (4.647 ms .. 4.768 ms) std dev 188.8 μs (143.7 μs .. 235.5 μs) variance introduced by outliers: 20% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing model count/100x10 time 55.67 ms (53.85 ms .. 57.68 ms) 0.995 R² (0.986 R² .. 0.999 R²) mean 55.03 ms (51.81 ms .. 56.67 ms) std dev 4.023 ms (2.152 ms .. 6.421 ms) variance introduced by outliers: 23% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x1 time 885.4 μs (873.7 μs .. 898.4 μs) 0.998 R² (0.997 R² .. 0.999 R²) mean 909.3 μs (899.6 μs .. 923.9 μs) std dev 40.42 μs (29.71 μs .. 61.27 μs) variance introduced by outliers: 36% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x10 time 4.669 ms (4.463 ms .. 4.850 ms) 0.991 R² (0.985 R² .. 0.995 R²) mean 4.673 ms (4.590 ms .. 4.754 ms) std dev 264.4 μs (226.1 μs .. 318.1 μs) variance introduced by outliers: 34% (moderately inflated) benchmarking mkPersist/Non-Null Fields/Increasing field count/10x100 time 43.01 ms (41.66 ms .. 44.14 ms) 0.997 R² (0.992 R² .. 0.999 R²) mean 42.88 ms (40.65 ms .. 44.22 ms) std dev 3.305 ms (1.574 ms .. 5.780 ms) variance introduced by outliers: 27% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/20x10 time 11.38 ms (11.18 ms .. 11.68 ms) 0.995 R² (0.985 R² .. 0.999 R²) mean 11.16 ms (10.97 ms .. 11.41 ms) std dev 603.2 μs (391.3 μs .. 912.9 μs) variance introduced by outliers: 26% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/40x10 time 24.00 ms (23.56 ms .. 24.38 ms) 0.999 R² (0.997 R² .. 0.999 R²) mean 23.97 ms (23.74 ms .. 24.24 ms) std dev 538.8 μs (409.6 μs .. 720.3 μs) benchmarking mkPersist/Nullable/Increasing model count/60x10 time 39.98 ms (37.68 ms .. 43.16 ms) 0.988 R² (0.976 R² .. 0.999 R²) mean 36.94 ms (36.04 ms .. 38.32 ms) std dev 2.173 ms (1.135 ms .. 3.656 ms) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/80x10 time 51.12 ms (44.79 ms .. 57.38 ms) 0.969 R² (0.915 R² .. 0.998 R²) mean 56.90 ms (53.41 ms .. 60.70 ms) std dev 6.589 ms (4.712 ms .. 8.849 ms) variance introduced by outliers: 40% (moderately inflated) benchmarking mkPersist/Nullable/Increasing model count/100x10 time 60.83 ms (55.87 ms .. 65.23 ms) 0.991 R² (0.983 R² .. 0.999 R²) mean 63.33 ms (59.62 ms .. 65.63 ms) std dev 5.272 ms (2.846 ms .. 8.609 ms) variance introduced by outliers: 24% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x20 time 9.925 ms (9.701 ms .. 10.16 ms) 0.995 R² (0.991 R² .. 0.998 R²) mean 10.15 ms (9.972 ms .. 10.31 ms) std dev 460.9 μs (371.1 μs .. 571.1 μs) variance introduced by outliers: 19% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x40 time 19.03 ms (18.30 ms .. 19.67 ms) 0.994 R² (0.988 R² .. 0.997 R²) mean 20.77 ms (19.98 ms .. 22.18 ms) std dev 2.346 ms (1.350 ms .. 3.393 ms) variance introduced by outliers: 51% (severely inflated) benchmarking mkPersist/Nullable/Increasing field count/10x60 time 29.54 ms (28.63 ms .. 30.63 ms) 0.996 R² (0.993 R² .. 0.998 R²) mean 29.85 ms (29.35 ms .. 30.35 ms) std dev 1.064 ms (835.8 μs .. 1.455 ms) variance introduced by outliers: 11% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x80 time 39.68 ms (38.06 ms .. 41.69 ms) 0.993 R² (0.985 R² .. 0.998 R²) mean 39.61 ms (37.67 ms .. 40.74 ms) std dev 3.070 ms (1.579 ms .. 5.208 ms) variance introduced by outliers: 25% (moderately inflated) benchmarking mkPersist/Nullable/Increasing field count/10x100 time 48.92 ms (46.41 ms .. 50.57 ms) 0.996 R² (0.993 R² .. 0.998 R²) mean 49.09 ms (46.21 ms .. 50.95 ms) std dev 4.472 ms (2.372 ms .. 8.241 ms) variance introduced by outliers: 29% (moderately inflated) ``` Co-authored-by: Matt Parsons <parsonsmatt@gmail.com>
This PR uses StandaloneDeriving to avoid the handwritten instances that currently exist in persistent-template.
In addition, it uses deriving strategies to specify that GeneralizedNewtypeDeriving should be used to derive the instances. This fixes the long-standing issue that derivation would fail if DeriveAnyClass was enabled
DeriveAnyClass
enabled #578I think this is working, but I'd ideally like to test in a larger project to make sure this doesn't massively increase compile times or break any derived instances.
Before submitting your PR, check that you've:
@since
declarations to the Haddock (no new APIs)After submitting your PR: