Skip to content

Commit

Permalink
touchup
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindberg committed Dec 17, 2023
1 parent f89bcd4 commit 9f00817
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
21 changes: 17 additions & 4 deletions site/blog/2023-12-17-the-cost-of-implicits.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for having a codebase full of implicits which need to be resolved. Read on to se
Typo is a code-generation library for working with PostgreSQL in Scala.
You can read more in the [introduction](https://oyvindberg.github.io/typo/docs/).

It was built to replace huge swatches of boilerplate in applications,
It was built to replace huge swathes of boilerplate in applications,
as well as to provide sorely needed type-safety to avoid having to test everything.

A crucial design goal was to fit into your system such as it is.
Expand Down Expand Up @@ -73,6 +73,15 @@ import EmailaddressRowUnsaved from '!!raw-loader!@site/blog/emailaddress/Emailad
<details><summary>EmailaddressRow.scala</summary><CodeBlock language="yaml" children={EmailaddressRow}/></details>
<details><summary>EmailaddressRowUnsaved.scala</summary><CodeBlock language="yaml" children={EmailaddressRowUnsaved}/></details>

In total it's about this much:
```
--------------------------------------------------------------------------------
Language Files Lines Blank Comment Code
--------------------------------------------------------------------------------
Scala 1052 47011 3215 7436 36360
--------------------------------------------------------------------------------
```

## Initial comparison of compile times

Each benchmark is run three times, and in the graphs you can choose to se minimum or average compile times.
Expand Down Expand Up @@ -227,9 +236,13 @@ anorm,scala213,true,7622,7593
anorm,scala3,true,7050,6948
`}</ScalaCompileTimesChart>

This brings the compile time for doobie down to about the same as for anorm and zio-jdbc.
### Observations

- This brings the compile time for doobie down to about the same as for anorm and zio-jdbc!
- We lose a handsome amount of compile time for zio-jdbc and anorm. But it's less clear that it's enough to be worth inlining manually.
It's a great conclusion actually, resolving implicits is fast as long as it's a straightforward process.

Great! So what is going on?
### Great! So what is going on with doobie then?

I honestly haven't dug into all the details, but I have a guess which looks obvious.
In order to interpolate values into an SQL query, doobie needs to resolve a chain of implicits instead of just one.
Expand Down Expand Up @@ -310,7 +323,7 @@ I excluded them for the text above since there was nothing interesting to say ab
You can see how "inline implicits" mode also speeds up compilation of these JSON codecs.

### Benchmark limitations
I think part of this improvement from "inlined implicits" is due to the fact that the compiler is a bit warmer the second time around.
I think part of this improvement from "inlined implicits" is due to the fact that the compiler is a bit warmer since it will just have finished compiling without inlined implicits.

Note specifically that we get faster compiles for "baseline" with "inlined implicits" mode, although the generated code is the same.

Expand Down
24 changes: 9 additions & 15 deletions site/src/components/ScalaCompileTimesChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,17 @@ const ScalaCompileTimesChart = ({id, children: csvData}) => {
: 'Minimum Compile Times (Seconds)',
},
scales: {
xAxes: [
{
stacked: true,
ticks: {
autoSkip: false,
},
y: {
stacked: false,
ticks: {
beginAtZero: true,
// callback: value => value + 's',
},
],
yAxes: [
{
stacked: false,
ticks: {
beginAtZero: true,
callback: value => value + 's',
},
title: {
display: true,
text: 'Milliseconds',
},
],
},
},
},
});
Expand Down

0 comments on commit 9f00817

Please sign in to comment.