Skip to content

Commit

Permalink
Uses strict Map to fix a compile time regression (#4521)
Browse files Browse the repository at this point in the history
For extremely large files (14K lines) with a lot of types and instances
memory increases dramatically using Lazy Maps, causing swapping and an
big increase in compilation time.

Switching to a strict map brings compilation performance close to 15.2
levels.

Fixes #4491
  • Loading branch information
mjrussell committed Nov 24, 2023
1 parent a6feba0 commit a915253
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.d/fix_compilation_regression-4491.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* Fix a compilation memory regression for very large files

When compiling a a very large file (>12K lines)
the CSE pass could balloon memory and result in increased
compilation times.

This fix uses a strict Map instead of a lazy Map to avoid
building up unnecessary thunks during the optimization pass.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ If you would prefer to use different terms, please use the section below instead
| [@milesfrain](https://github.com/milesfrain) | Miles Frain | [MIT license] |
| [@MiracleBlue](https://github.com/MiracleBlue) | Nicholas Kircher | [MIT license] |
| [@mjgpy3](https://github.com/mjgpy3) | Michael Gilliland | [MIT license] |
| [@mjrussell](https://github.com/mjrussell) | Matthew Russell | [MIT license] |
| [@MonoidMusician](https://github.com/MonoidMusician) | Verity Scheel | [MIT license] |
| [@mpietrzak](https://github.com/mpietrzak) | Maciej Pietrzak | [MIT license] |
| [@mrhania](https://github.com/mrhania) | Łukasz Hanuszczak | [MIT license] |
Expand Down
4 changes: 2 additions & 2 deletions src/Language/PureScript/CoreFn/CSE.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Data.Bitraversable (bitraverse)
import Data.Functor.Compose (Compose(..))
import Data.IntMap.Monoidal qualified as IM
import Data.IntSet qualified as IS
import Data.Map qualified as M
import Data.Map.Strict qualified as M
import Data.Maybe (fromJust)
import Data.Semigroup (Min(..))
import Data.Semigroup.Generic (GenericSemigroupMonoid(..))
Expand Down Expand Up @@ -216,7 +216,7 @@ newScope isTopLevel body = local goDeeper $ do
if isTopLevel
then env{ _depth = depth', _deepestTopLevelScope = depth' }
else env{ _depth = depth' }
where
where
depth' = succ _depth

-- |
Expand Down

0 comments on commit a915253

Please sign in to comment.