Title: Regression in compilation time and memory in Purescript > 0.15.2 · Issue #4491 · purescript/purescript · GitHub
Open Graph Title: Regression in compilation time and memory in Purescript > 0.15.2 · Issue #4491 · purescript/purescript
X Title: Regression in compilation time and memory in Purescript > 0.15.2 · Issue #4491 · purescript/purescript
Description: Description Regression in compilation time and memory in Purescript 0.15.9 (likely introduced in Purescript 0.15.3 by #3915). At Lumi, we have a large "Types" which is generated from Haskell datatypes and custom generic code. This file i...
Open Graph Description: Description Regression in compilation time and memory in Purescript 0.15.9 (likely introduced in Purescript 0.15.3 by #3915). At Lumi, we have a large "Types" which is generated from Haskell dataty...
X Description: Description Regression in compilation time and memory in Purescript 0.15.9 (likely introduced in Purescript 0.15.3 by #3915). At Lumi, we have a large "Types" which is generated from Hask...
Opengraph URL: https://github.com/purescript/purescript/issues/4491
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Regression in compilation time and memory in Purescript > 0.15.2","articleBody":"## Description\r\n\r\nRegression in compilation time and memory in Purescript 0.15.9 (likely introduced in Purescript 0.15.3 by https://github.com/purescript/purescript/pull/3915). \r\n\r\nAt Lumi, we have a large \"Types\" which is generated from Haskell datatypes and custom generic code. This file is always the slowest in our compilation chain, however it significantly worsened when we tried upgrading from 0.14.7. The purs compiler RAM usage was most significant, growing to 30GB of ram during the compilation phase. @MonoidMusician recommended I try Purescript 0.15.2, and while there was a small increase from 0.14.7, the RAM was only 2GB during compilation of the large types file.\r\n\r\n## To Reproduce\r\n\r\nThe Types file has 430 newtypes and 250 data type definitions and otherwise contains only instances. A sample newtype definition looks like:\r\n\r\n```purescript\r\nnewtype Address\r\n = Address\r\n { \"id\" :: Key Address\r\n , \"status\" :: LocationStatus\r\n , \"name\" :: Maybe String\r\n , \"type_\" :: Maybe AddressType\r\n , \"fullName\" :: String\r\n , \"company\" :: Maybe String\r\n , \"address\" :: String\r\n , \"aptSuite\" :: Maybe String\r\n , \"city\" :: String\r\n , \"country\" :: String\r\n , \"state\" :: Maybe String\r\n , \"postalCode\" :: Maybe String\r\n }\r\n\r\nderive instance genericAddress :: Generic Address _\r\nderive instance newtypeAddress :: Newtype Address _\r\n\r\ninstance decodeAddress :: Decode Address where\r\n decode = genericDecode jsonOptions\r\n\r\ninstance encodeAddress :: Encode Address where\r\n encode = genericEncode jsonOptions\r\n```\r\nThe Encode/Decode instances use purescript-foreign (the working groups port to 15.x). At first I thought maybe this library's approach was introducing a regression but I did a POC to switch to argonaught generics and found similar, if not slightly worse compiler performance.\r\n\r\nThere are also some polymorphic types such as:\r\n```purescript\r\nnewtype ApiResponse a1 a0\r\n = ApiResponse\r\n { \"warnings\" :: Array a1\r\n , \"result\" :: a0\r\n }\r\n\r\nderive instance genericApiResponse :: Generic (ApiResponse a1 a0) _\r\nderive instance newtypeApiResponse :: Newtype (ApiResponse a1 a0) _\r\n\r\ninstance decodeApiResponse :: (Decode a1, Decode a0, DecodeWithOptions a1, DecodeWithOptions a0) => Decode (ApiResponse a1 a0) where\r\n decode = genericDecode jsonOptions\r\n\r\ninstance encodeApiResponse :: (Encode a1, Encode a0, EncodeWithOptions a1, EncodeWithOptions a0) => Encode (ApiResponse a1 a0) where\r\n encode = genericEncode jsonOptions\r\n```\r\n\r\nA sample data type is:\r\n\r\n```purescript\r\ndata ClientUpdate\r\n = ClientSetAssignedUser\r\n (Maybe (Key User))\r\n | ClientReactivate\r\n | ClientDeactivate\r\n ClientDeactivation\r\n\r\nderive instance genericClientUpdate :: Generic ClientUpdate _\r\n\r\ninstance decodeClientUpdate :: Decode ClientUpdate where\r\n decode = genericDecode jsonOptions\r\n\r\ninstance encodeClientUpdate :: Encode ClientUpdate where\r\n encode = genericEncode jsonOptions\r\n```\r\n\r\n\r\n## Expected behavior\r\n\r\nThe purs compiler takes no more than 2GB during compilation. \r\n\r\n## Additional context\r\n\r\nThis has been tested so far on a Mac M1. With Purescript 15.9 I was using the arm binaries and for 15.2 the x86 with rosetta emulation. I can also get some statistics on Linux if that would be helpful.\r\n\r\nWe also attempted generation of non-generic encodings. This definitely had a large impact on compilation memory and time, bringing it down to a more manageable ~8GB RAM but still elevated more than 15.2.\r\n\r\n## PureScript version\r\n\r\n0.15.9\r\n","author":{"url":"https://github.com/mjrussell","@type":"Person","name":"mjrussell"},"datePublished":"2023-07-21T16:09:18Z","url":"https://github.com/purescript/purescript/issues/4491"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8a4d2792-e895-e2bb-e75d-e115e7900408 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 90B8:21E3E7:61D90C:837CD1:6B00D2EA |
| html-safe-nonce | dcc5597b86c865c01eff06221a64b99260d06f64a8274f000151573ee9d96438 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MEI4OjIxRTNFNzo2MUQ5MEM6ODM3Q0QxOjZCMDBEMkVBIiwidmlzaXRvcl9pZCI6IjMxNzkzNzY5Nzg5MTAzMDI5NTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 65955239bb31cb3195c88d657b136741a3a7bcf3c5ada40326c6373a79f7e0b3 |
| hovercard-subject-tag | issue:1816057570 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript/purescript/4491/issue_layout |
| twitter:image | https://opengraph.githubassets.com/95ad24c0982916474d006c760c7598a733518f552b2f324003106c2507f127cf/purescript/purescript/issues/4491 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/95ad24c0982916474d006c760c7598a733518f552b2f324003106c2507f127cf/purescript/purescript/issues/4491 |
| og:image:alt | Description Regression in compilation time and memory in Purescript 0.15.9 (likely introduced in Purescript 0.15.3 by #3915). At Lumi, we have a large "Types" which is generated from Haskell dataty... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mjrussell |
| hostname | github.com |
| expected-hostname | github.com |
| None | 85bbdfe2b6ba16e234513bc6ceff5d848ef8449820c900692a2b4e67061931e5 |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript/purescript git https://github.com/purescript/purescript.git |
| octolytics-dimension-user_id | 6556677 |
| octolytics-dimension-user_login | purescript |
| octolytics-dimension-repository_id | 13206906 |
| octolytics-dimension-repository_nwo | purescript/purescript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 13206906 |
| octolytics-dimension-repository_network_root_nwo | purescript/purescript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4943239a6d2c591325dad6e5c313e1cafda877f6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width