git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Mike Hommey <mh@glandium.org>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Phillip Wood <phillip.wood123@gmail.com>,
	Jeff King <peff@peff.net>, Dan Jacques <dnj@google.com>,
	Eric Wong <e@80x24.org>, Jonathan Nieder <jrnieder@gmail.com>
Subject: Re: [PATCH v3 18/23] Makefiles: add and use wildcard "mkdir -p" template
Date: Wed, 17 Nov 2021 18:39:47 +0900	[thread overview]
Message-ID: <20211117093947.ifkrvddmiiu3hg2v@glandium.org> (raw)
In-Reply-To: <211117.86wnl76sal.gmgdl@evledraar.gmail.com>

On Wed, Nov 17, 2021 at 10:26:27AM +0100, Ævar Arnfjörð Bjarmason wrote:
> 
> On Wed, Nov 17 2021, Mike Hommey wrote:
> 
> > On Tue, Nov 16, 2021 at 01:00:18PM +0100, Ævar Arnfjörð Bjarmason wrote:
> >> 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
> >> 8650c6298c1 (doc lint: make "lint-docs" non-.PHONY, 2021-10-15).
> >> 
> >> As seen in 4c64fb5aad9 (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 thatnoted 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 hyperfine -L rev HEAD~0,HEAD~1 -b 'make -C Documentation lint-docs' -p 'rm -rf Documentation/.build' 'make -C Documentation lint-docs'
> >>     Benchmark 1: make -C Documentation lint-docs' in 'HEAD~0
> >>       Time (mean ± σ):      2.129 s ±  0.011 s    [User: 1.840 s, System: 0.321 s]
> >>       Range (min … max):    2.121 s …  2.158 s    10 runs
> >> 
> >>     Benchmark 2: make -C Documentation lint-docs' in 'HEAD~1
> >>       Time (mean ± σ):      2.659 s ±  0.002 s    [User: 2.306 s, System: 0.397 s]
> >>       Range (min … max):    2.657 s …  2.662 s    10 runs
> >> 
> >>     Summary
> >>       'make -C Documentation lint-docs' in 'HEAD~0' ran
> >>         1.25 ± 0.01 times faster than 'make -C Documentation 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.
> >
> > Something else that is racy is that $(wildcard) might be saying the
> > directory doesn't exist while there's another make subprocess that has
> > already started spawning `mkdir -p` for that directory.
> > That doesn't make a huge difference, but you can probably still end up
> > with multiple `mkdir -p` runs for the same directory.
> >
> > I think something like the following could work while avoiding those
> > races:
> >
> > define create_parent_dir_RULE
> > $(1): | $(dir $(1)).
> > ALL_DIRS += $(dir $(1))
> > endef
> >
> > define create_parent_dir_TARGET
> > $(1)/.: $(dir $(1)).
> > 	echo mkdir $$(@D)

erf, s/echo //

> > endef
> >
> > $(eval $(call create_parent_dir_RULE, first/path/file))
> > $(eval $(call create_parent_dir_RULE, second/path/file))
> > # ...
> >
> > $(foreach dir,$(sort $(ALL_DIRS)),$(eval $(call create_parent_dir_TARGET,$(dir:%/=%))))
> 
> I think the "race" just isn't a problem, and makes managing this much
> simpler.
> 
> I.e. we already rely on "mkdir -p" not failing on an existing directory,
> so the case where we redundantly try to create a directory that just got
> created by a concurrent process is OK, and as the quoted benchmark shows
> is much faster than a similar (but not quite the same as) a
> dependency-based implementaiton.
> 
> I haven't implemented your solution, but it seems to be inherently more
> complex.
> 
> I.e. with the one I've got you just stick the "mkdir if needed"
> one-liner in each rule, with yours you'll need to accumulate things in
> ALL_DIRS, and have some foreach somewhere or dependency relationship to
> create those beforehand if they're nested, no?

For each rule, it would also be a oneliner to add above the rule. The rest
would be a prelude and a an epilogue to stick somewhere in the Makefile.

  reply	other threads:[~2021-11-17  9:41 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-06 21:03 [PATCH 00/16] Makefiles: dependency correctness & speedup Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 01/16] Makefile: don't set up "perl/build" rules under NO_PERL=Y Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 02/16] Makefile: clean perl/build/ even with NO_PERL=Y Ævar Arnfjörð Bjarmason
2021-11-09 23:10   ` Junio C Hamano
2021-11-06 21:03 ` [PATCH 03/16] Makefile: remove "mv $@ $@+" dance redundant to .DELETE_ON_ERROR Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 04/16] Makefile: move Perl-only variable assignments under !NO_PERL Ævar Arnfjörð Bjarmason
2021-11-09 23:22   ` Junio C Hamano
2021-11-06 21:03 ` [PATCH 05/16] Makefile: correct "GIT-PERL-{DEFINES,HEADER}" dependency graph Ævar Arnfjörð Bjarmason
2021-11-07  1:51   ` Eric Sunshine
2021-11-06 21:03 ` [PATCH 06/16] Makefile: don't have Perl over-depend on GIT-BUILD-OPTIONS Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 07/16] Makefile: create a GIT-PYTHON-DEFINES, like "PERL" Ævar Arnfjörð Bjarmason
2021-11-07  1:55   ` Eric Sunshine
2021-11-06 21:03 ` [PATCH 08/16] Makefile: stop needing @@GIT_VERSION@@ in *.perl scripts Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 09/16] Makefiles: add "shared.mak", move ".DELETE_ON_ERROR" to it Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 10/16] Makefile: move $(comma), $(empty) and $(space) to shared.mak Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 11/16] Makefile: re-add and use the "shellquote" macros Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 12/16] Makefile: add a "TRACK_template" for GIT-*{FLAGS,DEFINES,...} Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 13/16] Makefile: add "$(QUIET)" boilerplate to shared.mak Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 14/16] Makefile: use $(wspfx) for $(QUIET...) in shared.mak Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 15/16] Makefiles: add and use wildcard "mkdir -p" template Ævar Arnfjörð Bjarmason
2021-11-06 21:03 ` [PATCH 16/16] Makefile: don't invoke msgfmt with --statistics Ævar Arnfjörð Bjarmason
2021-11-12 21:48 ` [PATCH v2 00/18] Makefiles: dependency correctness & speedup Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 01/18] Makefile: don't invoke msgfmt with --statistics Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 02/18] Makefile: don't set up "perl/build" rules under NO_PERL=Y Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 03/18] Makefile: use "=" not ":=" for po/* and perl/* Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 04/18] Makefile: clean perl/build/ even with NO_PERL=Y Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 05/18] Makefile: remove "mv $@ $@+" dance redundant to .DELETE_ON_ERROR Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 06/18] Makefile: guard Perl-only variable assignments Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 07/18] Makefile: change "ifndef NO_PERL" to "ifdef NO_PERL" Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 08/18] Makefile: adjust Perl-related comments & whitespace Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 09/18] Makefile: correct "GIT-PERL-{DEFINES,HEADER}" dependency graph Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 10/18] Makefile: create a GIT-PYTHON-DEFINES, like "PERL" Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 11/18] Makefile: stop needing @@GIT_VERSION@@ in *.perl scripts Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 12/18] Makefiles: add "shared.mak", move ".DELETE_ON_ERROR" to it Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 13/18] Makefile: move $(comma), $(empty) and $(space) to shared.mak Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 14/18] Makefile: re-add and use the "shellquote" macros Ævar Arnfjörð Bjarmason
2021-11-12 21:48   ` [PATCH v2 15/18] Makefile: add a "TRACK_template" for GIT-*{FLAGS,DEFINES,...} Ævar Arnfjörð Bjarmason
2021-11-12 21:49   ` [PATCH v2 16/18] Makefile: add "$(QUIET)" boilerplate to shared.mak Ævar Arnfjörð Bjarmason
2021-11-12 21:49   ` [PATCH v2 17/18] Makefile: use $(wspfx) for $(QUIET...) in shared.mak Ævar Arnfjörð Bjarmason
2021-11-12 21:49   ` [PATCH v2 18/18] Makefiles: add and use wildcard "mkdir -p" template Ævar Arnfjörð Bjarmason
2021-11-16 12:00   ` [PATCH v3 00/23] Makefile: dependency fixes, make noop runtime ~1.4x faster Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 01/23] Makefile: don't invoke msgfmt with --statistics Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 02/23] Makefile: don't set up "perl/build" rules under NO_PERL=Y Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 03/23] Makefile: use "=" not ":=" for po/* and perl/* Ævar Arnfjörð Bjarmason
2021-11-17  1:57       ` Mike Hommey
2021-11-16 12:00     ` [PATCH v3 04/23] Makefile: clean perl/build/ even with NO_PERL=Y Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 05/23] Makefile: remove "mv $@ $@+" dance redundant to .DELETE_ON_ERROR Ævar Arnfjörð Bjarmason
2021-11-17  2:01       ` Mike Hommey
2021-11-17  9:20         ` Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 06/23] Makefile: guard Perl-only variable assignments Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 07/23] Makefile: change "ifndef NO_PERL" to "ifdef NO_PERL" Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 08/23] Makefile: adjust Perl-related comments & whitespace Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 09/23] Makefile: correct "GIT-PERL-{DEFINES,HEADER}" dependency graph Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 10/23] Makefile: create a GIT-PYTHON-DEFINES, like "PERL" Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 11/23] Makefile: stop needing @@GIT_VERSION@@ in *.perl scripts Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 12/23] Makefiles: add "shared.mak", move ".DELETE_ON_ERROR" to it Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 13/23] Makefile: move $(comma), $(empty) and $(space) to shared.mak Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 14/23] Makefile: re-add and use the "shellquote" macros Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 15/23] Makefile: add a "TRACK_template" for GIT-*{FLAGS,DEFINES,...} Ævar Arnfjörð Bjarmason
2021-11-17  2:19       ` Mike Hommey
2021-11-17  9:24         ` Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 16/23] Makefile: add "$(QUIET)" boilerplate to shared.mak Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 17/23] Makefile: use $(wspfx) for $(QUIET...) in shared.mak Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 18/23] Makefiles: add and use wildcard "mkdir -p" template Ævar Arnfjörð Bjarmason
2021-11-17  2:51       ` Mike Hommey
2021-11-17  9:26         ` Ævar Arnfjörð Bjarmason
2021-11-17  9:39           ` Mike Hommey [this message]
2021-11-17 11:52             ` Ævar Arnfjörð Bjarmason
2021-11-18  0:00               ` Mike Hommey
2021-11-18 13:05                 ` Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 19/23] Makefile: correct the dependency graph of hook-list.h Ævar Arnfjörð Bjarmason
2021-11-17  2:52       ` Mike Hommey
2021-11-16 12:00     ` [PATCH v3 20/23] Makefile: use $(file) I/O instead of "FORCE" when possible Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 21/23] Makefile: disable GNU make built-in wildcard rules Ævar Arnfjörð Bjarmason
2021-11-17  3:00       ` Mike Hommey
2021-11-17  9:47         ` Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 22/23] Makefile: define $(LIB_H) in terms of $(FIND_SOURCE_FILES) Ævar Arnfjörð Bjarmason
2021-11-16 12:00     ` [PATCH v3 23/23] Makefile: move ".SUFFIXES" rule to shared.mak Ævar Arnfjörð Bjarmason
2021-11-17 10:19     ` [PATCH v4 00/23] Makefile: dependency fixes, make noop runtime ~1.4x faster Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 01/23] Makefile: don't invoke msgfmt with --statistics Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 02/23] Makefile: don't set up "perl/build" rules under NO_PERL=Y Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 03/23] Makefile: use "=" not ":=" for po/* and perl/* Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 04/23] Makefile: clean perl/build/ even with NO_PERL=Y Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 05/23] Makefile: remove "mv $@ $@+" dance redundant to .DELETE_ON_ERROR Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 06/23] Makefile: guard Perl-only variable assignments Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 07/23] Makefile: change "ifndef NO_PERL" to "ifdef NO_PERL" Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 08/23] Makefile: adjust Perl-related comments & whitespace Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 09/23] Makefile: correct "GIT-PERL-{DEFINES,HEADER}" dependency graph Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 10/23] Makefile: create a GIT-PYTHON-DEFINES, like "PERL" Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 11/23] Makefile: stop needing @@GIT_VERSION@@ in *.perl scripts Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 12/23] Makefiles: add "shared.mak", move ".DELETE_ON_ERROR" to it Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 13/23] Makefile: move $(comma), $(empty) and $(space) to shared.mak Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 14/23] Makefile: re-add and use the "shellquote" macros Ævar Arnfjörð Bjarmason
2021-12-13 23:09         ` Junio C Hamano
2021-12-14  0:31           ` Junio C Hamano
2021-11-17 10:20       ` [PATCH v4 15/23] Makefile: add a "TRACK_template" for GIT-*{FLAGS,DEFINES,...} Ævar Arnfjörð Bjarmason
2021-11-19  6:45         ` Junio C Hamano
2021-11-19  6:56           ` Junio C Hamano
2021-11-19  7:30             ` Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 16/23] Makefile: add "$(QUIET)" boilerplate to shared.mak Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 17/23] Makefile: use $(wspfx) for $(QUIET...) in shared.mak Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 18/23] Makefiles: add and use wildcard "mkdir -p" template Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 19/23] Makefile: correct the dependency graph of hook-list.h Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 20/23] Makefile: use $(file) I/O instead of "FORCE" when possible Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 21/23] Makefile: disable GNU make built-in wildcard rules Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 22/23] Makefile: define $(LIB_H) in terms of $(FIND_SOURCE_FILES) Ævar Arnfjörð Bjarmason
2021-11-17 10:20       ` [PATCH v4 23/23] Makefile: move ".SUFFIXES" rule to shared.mak Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211117093947.ifkrvddmiiu3hg2v@glandium.org \
    --to=mh@glandium.org \
    --cc=avarab@gmail.com \
    --cc=dnj@google.com \
    --cc=e@80x24.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=phillip.wood123@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).