Commit 0b6d0bc
Makefiles: add and use wildcard "mkdir -p" template
Add a template to do the "mkdir -p" of $(@d) (the parent dir of $@)
for us, and use it for the "make lint-docs" targets I added in
8650c62 (doc lint: make "lint-docs" non-.PHONY, 2021-10-15).
As seen in 4c64fb5 (Documentation/Makefile: fix lint-docs mkdir
dependency, 2021-10-26) maintaining these manual lists of parent
directory dependencies is fragile, in addition to being obviously
verbose.
I used this pattern at the time because I couldn't find another method
than "order-only" prerequisites to avoid doing a "mkdir -p $(@d)" for
every file being created, which as noted in [1] would be significantly
slower.
But as it turns out we can use this neat trick of only doing a "mkdir
-p" if the $(wildcard) macro tells us the path doesn't exist. A re-run
of a performance test similar to that noted downthread of [1] in [2]
shows that this is faster, in addition to being less verbose and more
reliable (this uses my "git-hyperfine" thin wrapper for "hyperfine"[3]):
$ git -c hyperfine.hook.setup= hyperfine -L rev HEAD~1,HEAD~0 -s 'make -C Documentation lint-docs' -p 'rm -rf Documentation/.build' 'make -C Documentation -j1 lint-docs'
Benchmark 1: make -C Documentation -j1 lint-docs' in 'HEAD~1
Time (mean ± σ): 2.914 s ± 0.062 s [User: 2.449 s, System: 0.489 s]
Range (min … max): 2.834 s … 3.020 s 10 runs
Benchmark 2: make -C Documentation -j1 lint-docs' in 'HEAD~0
Time (mean ± σ): 2.315 s ± 0.062 s [User: 1.950 s, System: 0.386 s]
Range (min … max): 2.229 s … 2.397 s 10 runs
Summary
'make -C Documentation -j1 lint-docs' in 'HEAD~0' ran
1.26 ± 0.04 times faster than 'make -C Documentation -j1 lint-docs' in 'HEAD~1'
So let's use that pattern both for the "lint-docs" target, and a few
miscellaneous other targets.
This method of creating parent directories is explicitly racy in that
we don't know if we're going to say always create a "foo" followed by
a "foo/bar" under parallelism, or skip the "foo" because we created
"foo/bar" first. In this case it doesn't matter for anything except
that we aren't guaranteed to get the same number of rules firing when
running make in parallel.
1. https://lore.kernel.org/git/211028.861r45y3pt.gmgdl@evledraar.gmail.com/
2. https://lore.kernel.org/git/211028.86o879vvtp.gmgdl@evledraar.gmail.com/
3. https://gitlab.com/avar/git-hyperfine/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>1 parent a9fda01 commit 0b6d0bc
3 files changed
+27
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | 437 | | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | 438 | | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | 439 | | |
455 | 440 | | |
| 441 | + | |
456 | 442 | | |
457 | 443 | | |
458 | 444 | | |
| |||
463 | 449 | | |
464 | 450 | | |
465 | 451 | | |
466 | | - | |
467 | | - | |
468 | 452 | | |
469 | | - | |
470 | 453 | | |
471 | 454 | | |
| 455 | + | |
472 | 456 | | |
473 | 457 | | |
474 | | - | |
475 | 458 | | |
476 | 459 | | |
477 | | - | |
478 | | - | |
479 | 460 | | |
480 | | - | |
481 | 461 | | |
482 | 462 | | |
| 463 | + | |
483 | 464 | | |
484 | 465 | | |
485 | 466 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2745 | 2745 | | |
2746 | 2746 | | |
2747 | 2747 | | |
2748 | | - | |
| 2748 | + | |
| 2749 | + | |
2749 | 2750 | | |
2750 | 2751 | | |
2751 | 2752 | | |
| |||
2761 | 2762 | | |
2762 | 2763 | | |
2763 | 2764 | | |
2764 | | - | |
| 2765 | + | |
| 2766 | + | |
2765 | 2767 | | |
2766 | 2768 | | |
2767 | 2769 | | |
2768 | 2770 | | |
2769 | 2771 | | |
2770 | 2772 | | |
2771 | | - | |
2772 | | - | |
| 2773 | + | |
| 2774 | + | |
2773 | 2775 | | |
2774 | 2776 | | |
2775 | 2777 | | |
| |||
2903 | 2905 | | |
2904 | 2906 | | |
2905 | 2907 | | |
2906 | | - | |
| 2908 | + | |
2907 | 2909 | | |
2908 | 2910 | | |
2909 | 2911 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| |||
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
0 commit comments