rrrene / credo

A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
http://credo-ci.org/
MIT License
4.91k stars 414 forks source link

Improve usage of Tasks #1111

Closed novaugust closed 7 months ago

novaugust commented 7 months ago

Similar to #1077, optimizes the use of streams of tasks in credo in a few more places.

in addition to swapping Enum.map(&Task.async(...)) -> Task.async_stream, this pr also removes ordering from the streams (where possible) for more slight performance gains (h/t @milmazz)

rrrene commented 7 months ago

Seems to improve performance :+1:

Can we have some real-world numbers regarding speed difference, like in #1077?

novaugust commented 7 months ago

running against 3842 files, it's negligible but there.

here's credo master, with credo's default checks enabled:

> # credo master
> hyperfine 'mix credo' -i --warmup 1
Benchmark 1: mix credo
  Time (mean ± σ):     24.770 s ±  0.331 s    [User: 187.391 s, System: 13.010 s]
  Range (min … max):   24.340 s … 25.235 s    10 runs

and here's against this branch:

> # Task.async_stream refactor
> hyperfine 'mix credo' -i --warmup 1
Benchmark 1: mix credo
  Time (mean ± σ):     24.077 s ±  0.421 s    [User: 182.291 s, System: 10.692 s]
  Range (min … max):   23.674 s … 24.633 s    10 runs

still, negligible enough that i'd understand not merging.

looking at just DuplicatedCode, a single-run test took it from 17412ms to 15451ms, but running it in isolation probably isn't the best test. the crux here is that the checks that are slow in my codebase aren't really affected by these changes, so i don't see much of a difference :)

rrrene commented 7 months ago

I'm sure merging this is worth the performance benefit. My preliminary tests all show good results.

I was just looking for some real world data (and maybe a check that earlier OTP versions are not getting slower). :+1: