softwaremill / diffx

Pretty diffs for scala case classes
Apache License 2.0
342 stars 30 forks source link

Investigate compilation overhead #24

Closed ghostbuster91 closed 3 years ago

ghostbuster91 commented 5 years ago

Write some performance tests to measure various things. Maybe look at magnolia tests for inspiration?

This article might be helpful while debugging: http://www.lsug.co.uk/workshop/scala/2019/07/21/workshop-run-scalac-run.html

francisdb commented 5 years ago

We just found out that adding diffx to one of our tests increased compile time from 9s to 37s. Most of the time spent in macro expansion and typer (magnolia?). So diffx is out for now...

adamw commented 5 years ago

That's an interesting turn of events, as magnolia was supposed to help exactly with that problem ;) But maybe the code we're generating is somehow complex to typecheck?

francisdb commented 5 years ago

some details on compiler perf for the module that got slowed down:

[info] time spent in implicits       : 26298 spans, ()40685.324ms (97,1%)
[info]   successful in scope         : 4602 spans, ()34438.572ms (82,2%)
[info]   failed in scope             : 21696 spans, ()15615.766ms (37,3%)
[info]   successful of type          : 6005 spans, ()40204.231ms (96,0%)
[info]   failed of type              : 15691 spans, ()195.332ms (0,5%)
[info]   assembling parts            : 605 spans, ()2892.693ms (6,9%)
[info]   matchesPT                   : 51482 spans, ()174.387ms (0,4%)
[info] time spent in macroExpand     : 8636 spans, ()34019.755ms (81,2%)

the test has about 10 cases doing play json ast diffs

ghostbuster91 commented 5 years ago

@francisdb Could you give some example of how big are your case classes?

francisdb commented 5 years ago

Hmm, some quite elaborate play json JsObject object, maybe comparable to this https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/intro-to-tweet-json#quotetweet (and using the workaround provided in #14 )

ghostbuster91 commented 5 years ago

It would be great to have some benchmarks run on CI so we won't introduce regression after we fix it. Here are some inspirations:

GMadorell commented 4 years ago

Offtopic: @francisdb we are using https://github.com/gnieh/diffson for diffing json ast's and it's working very well for us

adamw commented 4 years ago

@francisdb are you maybe also using the silencer plugin? See https://github.com/ghik/silencer/issues/45 why I suspect this might be connected :)

francisdb commented 4 years ago

Nope, we were not using that plugin

adamw commented 4 years ago

Well, was worth a shot ;)

ghostbuster91 commented 3 years ago

Hi, I know that it's been a while but finally I managed to fix it to certain degree. It turned out that switching from auto to semi-auto derivation drastically decreases compilation time, so from this time onward this will be the recommended way to use diffx.

ghostbuster91 commented 3 years ago

Closing as semi-auto solves that problem.