awakesecurity / proto3-suite

Haskell Protobuf Implementation
https://hackage.haskell.org/package/proto3-suite
Other
81 stars 56 forks source link

Avoid allocating intermediate field builder list. #245

Closed j6carey closed 1 year ago

j6carey commented 1 year ago

During encoding, we used to create a list of builders for the fields of a protobuf message and then make a call to mconcat on the message builder type. But mconcat is recursive and therefore cannot be inlined as such, and GHC seems reluctant to perform beta reduction on known constructors such as (:) across module boundaries.

Therefore this commit switches from "mconcat [x, y, z]" to "mappend (mappend x y) z" (for example). These appends are left associativity because the builder writes in reverse, starting with the rightmost field.