Projects STRLCPY graphql-engine Commits 6329092b
🤬
  • server: memoize in tableSelectColumnsEnum and mkNumericAggFields for more sharing

    PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6789
    GitOrigin-RevId: 4f2245a4b8156467fb33bb3c4b1325a945a9409d
  • Loading...
  • Brandon Simmons committed with hasura-bot 2 months ago
    6329092b
    1 parent 0b3f756e
  • ■ ■ ■ ■ ■ ■
    server/src-lib/Hasura/GraphQL/Schema/Select.hs
    skipped 909 lines
    910 910   mkNumericAggFields :: G.Name -> [ColumnInfo b] -> m [FieldParser n (IR.ColFld b)]
    911 911   mkNumericAggFields name
    912 912   | name == Name._sum = traverse mkColumnAggField
     913 + -- Memoize here for more sharing. Note: we can't do `P.memoizeOn 'mkNumericAggFields...`
     914 + -- due to stage restrictions, so just add a string key:
    913 915   | otherwise = traverse \columnInfo ->
    914  - pure $! do
    915  - let !cfcol = IR.CFCol (ciColumn columnInfo) (ciType columnInfo)
    916  - P.selection_
    917  - (ciName columnInfo)
    918  - (ciDescription columnInfo)
    919  - (P.nullable P.float)
    920  - $> cfcol
     916 + P.memoizeOn 'tableAggregationFields ("mkNumericAggFields" :: Text, columnInfo) $
     917 + -- CAREFUL!: below must only reference columnInfo else memoization key needs to be adapted
     918 + pure $! do
     919 + let !cfcol = IR.CFCol (ciColumn columnInfo) (ciType columnInfo)
     920 + P.selection_
     921 + (ciName columnInfo)
     922 + (ciDescription columnInfo)
     923 + (P.nullable P.float)
     924 + $> cfcol
    921 925   
    922 926   mkColumnAggField :: ColumnInfo b -> m (FieldParser n (IR.ColFld b))
    923 927   mkColumnAggField columnInfo = do
    skipped 338 lines
  • ■ ■ ■ ■ ■ ■
    server/src-lib/Hasura/GraphQL/Schema/Table.hs
     1 +{-# LANGUAGE TemplateHaskellQuotes #-}
     2 + 
    1 3  -- | Helper functions for generating the schema of database tables
    2 4  module Hasura.GraphQL.Schema.Table
    3 5   ( getTableGQLName,
    skipped 91 lines
    95 97   Just $
    96 98   G.Description $
    97 99   "select columns of table " <>> tableInfoName tableInfo
    98  - pure $
    99  - P.enum enumName description
    100  - <$> nonEmpty
    101  - [ ( define $ ciName column,
    102  - ciColumn column
    103  - )
    104  - | column <- columns
    105  - ]
     100 + -- We noticed many 'Definition's allocated, from 'define' below, so memoize
     101 + -- to gain more sharing and lower memory residency.
     102 + case nonEmpty $ map (define . ciName &&& ciColumn) columns of
     103 + Nothing -> pure Nothing
     104 + Just columnDefinitions ->
     105 + Just
     106 + <$> ( P.memoizeOn 'tableSelectColumnsEnum (enumName, description, columns) $
     107 + pure $
     108 + P.enum enumName description columnDefinitions
     109 + )
    106 110   where
    107 111   define name =
    108 112   P.Definition name (Just $ G.Description "column name") Nothing [] P.EnumValueInfo
    skipped 126 lines
  • ■ ■ ■ ■ ■ ■
    server/src-lib/Hasura/RQL/Types/Backend.hs
    skipped 84 lines
    85 85   Ord (TableName b),
    86 86   Ord (FunctionName b),
    87 87   Ord (ScalarType b),
     88 + Ord (Column b),
    88 89   Data (TableName b),
    89 90   Traversable (BooleanOperators b),
    90 91   FromJSON (BackendConfig b),
    skipped 39 lines
    130 131   Cacheable (BackendConfig b),
    131 132   Typeable (TableName b),
    132 133   Typeable (ConstraintName b),
     134 + Typeable (Column b),
    133 135   Typeable b,
    134 136   HasTag b,
    135 137   -- constraints of function argument
    skipped 142 lines
  • ■ ■ ■ ■ ■
    server/src-lib/Hasura/RQL/Types/Column.hs
    skipped 213 lines
    214 214   { _cmIsInsertable :: Bool,
    215 215   _cmIsUpdatable :: Bool
    216 216   }
    217  - deriving (Eq, Generic, Show)
     217 + deriving (Eq, Ord, Generic, Show)
    218 218   
    219 219  instance Cacheable ColumnMutability
    220 220   
    skipped 23 lines
    244 244   deriving (Generic)
    245 245   
    246 246  deriving instance Backend b => Eq (ColumnInfo b)
     247 + 
     248 +deriving instance Backend b => Ord (ColumnInfo b)
    247 249   
    248 250  deriving instance Backend b => Show (ColumnInfo b)
    249 251   
    skipped 50 lines
Please wait...
Page is in error, reload to recover