This makes hs2py output types like ht.TMaybeBool instead of ht.TMaybe(ht.TBool). The two have equivalent behaviour, but Python creates a new callable object at runtime for each instance of the second, because TMaybe is a higher order function.
This optimisation saves >500kB of heap for "import opcodes" for every Ganeti Python process. Signed-off-by: Brian Foley <[email protected]> --- src/Ganeti/THH/PyType.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Ganeti/THH/PyType.hs b/src/Ganeti/THH/PyType.hs index a3dbe44..5a3941c 100644 --- a/src/Ganeti/THH/PyType.hs +++ b/src/Ganeti/THH/PyType.hs @@ -78,6 +78,13 @@ instance Lift PyType where lift PTTupleOf = [| PTTupleOf |] instance PyValue PyType where + -- Use lib/ht.py type aliases to avoid Python creating redundant + -- new match functions for commonly used OpCode param types. + showValue (PTMaybe (PTOther "NonEmptyString")) = ht "MaybeString" + showValue (PTMaybe (PTOther "Bool")) = ht "MaybeBool" + showValue (PTMaybe PTDictOf) = ht "MaybeDict" + showValue (PTMaybe PTListOf) = ht "MaybeList" + showValue (PTMaybe x) = ptApp (ht "Maybe") [x] showValue (PTApp tf as) = ptApp (showValue tf) as showValue (PTOther i) = ht i -- 2.7.0.rc3.207.g0ac5344
