Skip to content

Commit

Permalink
Add performance tip
Browse files Browse the repository at this point in the history
  • Loading branch information
jilen committed Jul 11, 2022
1 parent 0fa92db commit a431190
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4619,6 +4619,43 @@ After:
[info] | INNER JOIN Address a ON a.ownerFk = p.id
```

# Compiler performance tip

Quill could be extremely slow while compling extremely large models.

For example, compiling a file with 20 query of a model of 100 fields may take one or two minutes.

Most time are wasted generating `QueryMeta` instance of every query. Because it is not reused by default.

This can be improved by adding a `QueryMeta` instance somewhere in the scope like this.

```scala

case class LargeModel(
field1: Long,
field2: String,
// ... more fields
)

// Prevent compiler use this macro expansion by default.
import ctx.{materializeQueryMeta => _, _}

// Note, this implicit instance must not have type annotion, otherwise related query will become dynamic query.
// Since quill needs the concrete type information generate by the whitebox macro
implicit val largeModelQueryMeta = ctx.materializeQueryMeta[LargeModel]

def queryById(id: Long): Future[Seq[LargeModel]] = {
ctx.run {
query[LargeModel].filter(_.id == lift(id))
}
}

// ... more queries

```

After doing this, compiling time dramatically reduce from 2 minutes to 20 seconds, which says 60x boost.

# Additional resources

## Templates
Expand Down

0 comments on commit a431190

Please sign in to comment.