Skip to content

Commit 790660b

Browse files
committed
feat: --threads flag
- Makes my life simpler when benchmarking
1 parent ea3418c commit 790660b

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

CHANGELOG.md

+38
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,44 @@ Types of changes
4444
1.07x faster,
4545
from 2m44s to 2m33s
4646

47+
- After profiling the code as suggested by
48+
[nnethercote's perf-book](https://nnethercote.github.io/perf-book/profiling.html)
49+
one critical path of Alejandra was identified an optimized,
50+
yielding huge performance boosts:
51+
52+
- x86_64-unknown-linux-gnu, 2.5x faster,
53+
from 0m8.381s to 0m3.410s
54+
55+
- x86_64-unknown-linux-musl, 2.3x faster,
56+
from 0m9.642s to 0m4.134s
57+
58+
- [On QEMU](https://www.qemu.org/) aarch64-unknown-linux-musl,
59+
2.4x faster,
60+
from 1m10s to 0m29s
61+
62+
- [On QEMU](https://www.qemu.org/) armv6l-unknown-linux-musleabihf,
63+
1.85x faster,
64+
from 7m41s to 4m8.399s
65+
66+
- [On QEMU](https://www.qemu.org/) armv7l-unknown-linux-musleabihf,
67+
1.88x faster,
68+
from 5m7s to 2m42.595s
69+
70+
- [On QEMU](https://www.qemu.org/) i686-unknown-linux-musl,
71+
1.65x faster,
72+
from 2m33s to 1m32.671s
73+
74+
In general this is an algorithmic improvement
75+
and therefore the following platforms should be faster as well
76+
by a similar ratio
77+
(not measured):
78+
79+
- aarch64-apple-darwin
80+
- x86_64-apple-darwin
81+
82+
- A `--threads` flag, so you can pick how many formatting threads to spawn.
83+
Defaults to the number of logical CPUs in your system.
84+
4785
## [0.6.0] - 2022-02-25
4886

4987
### Added

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ Please see: [CHANGELOG.md](./CHANGELOG.md).
207207

208208
| Logical Cores | Seconds |
209209
| :-----------: | :-----: |
210-
| 1 | 35 |
211-
| 2 | 18 |
212-
| 4 | 10 |
213-
| 8 | 10 |
214-
| 16 | 10 |
210+
| 1 | 15.1 |
211+
| 2 | 7.9 |
212+
| 4 | 5.4 |
213+
| 8 | 4.1 |
214+
| 16 | 3.6 |
215215

216216
[^semantic-changes]: The methodology to claim this is:
217217

src/alejandra_cli/src/cli.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ pub(crate) fn parse(args: Vec<String>) -> clap::ArgMatches {
2424
.arg(
2525
clap::Arg::new("check")
2626
.help("Check if the input is already formatted.")
27-
.long("--check"),
27+
.long("--check")
28+
.short('c'),
29+
)
30+
.arg(
31+
clap::Arg::new("threads")
32+
.default_value("0")
33+
.help(
34+
"Number of formatting threads to spawn. Defaults to the \
35+
number of logical CPUs.",
36+
)
37+
.long("--threads")
38+
.short('t')
39+
.takes_value(true),
2840
)
2941
.term_width(80)
3042
.after_help(indoc::indoc!(
@@ -310,6 +322,13 @@ pub fn main() -> std::io::Result<()> {
310322
let matches = crate::cli::parse(std::env::args().collect());
311323

312324
let check = matches.is_present("check");
325+
let threads = matches.value_of("threads").unwrap();
326+
let threads: usize = threads.parse().unwrap();
327+
328+
rayon::ThreadPoolBuilder::new()
329+
.num_threads(threads)
330+
.build_global()
331+
.unwrap();
313332

314333
let formatted_paths = match matches.values_of("include") {
315334
Some(include) => {

0 commit comments

Comments
 (0)