Skip to content

Commit

Permalink
Split syntax module to reduce compilation time (#1852)
Browse files Browse the repository at this point in the history
Hello,
Splitting `Swarm.Language.Syntax` into submodules reduces the compilation time quite a bit. Currently, it takes the most of time out of all the modules. Here's a chart:

![CleanShot 2024-05-17 at 17 09 38@2x](https://github.com/swarm-game/swarm/assets/15181803/fc2672ea-4032-4140-93e7-16d9d4aaea69)

That's ~20s for simplifier (with overall compilation time of 4.3 mins)

Just taking out the types and functions related to `Constants` and putting them in a separate module results in:

![CleanShot 2024-05-17 at 17 11 45@2x](https://github.com/swarm-game/swarm/assets/15181803/ac4c57e9-af46-4861-b305-8540c1b01bab)

Thats ~8.5 seconds for simplifier (with overall compilation time of 3.9 mins)

Just for added info, timings taken on a 2019 macbook with i7 processor (6 core and 32 GB RAM)

Changes include:
- `Swarm.Language.Syntax` split into the following modules:
  - `Swarm.Language.Syntax.Comments` - Types for working with comments.
  - `Swarm.Language.Syntax.Type` - Core types (`Syntax'`, `Term'` and `DelayType`)
  - `Swarm.Language.Syntax.Pattern` - Pattern synonyms for untyped terms
  - `Swarm.Language.Syntax.Loc` -  Types for working with location in source code (`SrcLoc` and related types)
  - `Swarm.Language.Syntax.Util` - Helper functions (Eg: `mkTuple`, `freeVarsS` etc)

Compilation chart after the split:

![CleanShot 2024-05-18 at 15 20 17@2x](https://github.com/swarm-game/swarm/assets/15181803/b6a138dd-c0a3-416f-a620-2d82cb418c7d)

`Swarm.Language.Syntax` is no longer the most time taking module.

Closes #1844
  • Loading branch information
nitinprakash96 authored May 18, 2024
1 parent 76958a4 commit 8ad4efe
Show file tree
Hide file tree
Showing 20 changed files with 1,528 additions and 1,351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Linear (V2)
import Swarm.Game.Location
import Swarm.Game.Robot
import Swarm.Game.Universe (Cosmic, planar)
import Swarm.Language.Direction
import Swarm.Language.Syntax.Direction

-- |
-- Computes the relative offset vector between a 'Robot' and a 'Location'
Expand Down
2 changes: 1 addition & 1 deletion src/swarm-engine/Swarm/Game/Step/Util/Inspect.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Swarm.Game.Robot
import Swarm.Game.State
import Swarm.Game.State.Robot
import Swarm.Game.Universe
import Swarm.Language.Direction
import Swarm.Language.Syntax.Direction
import Swarm.Util (listEnums)

-- * World queries
Expand Down
2 changes: 1 addition & 1 deletion src/swarm-engine/Swarm/Game/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Swarm.Game.Entity
import Swarm.Game.Location
import Swarm.Game.Robot
import Swarm.Game.Scenario.Topography.Area (AreaDimensions (..))
import Swarm.Language.Direction
import Swarm.Language.Syntax.Direction
import Swarm.Language.Value

-- * Patterns
Expand Down
Loading

0 comments on commit 8ad4efe

Please sign in to comment.