From: Karthik Nayak Date: Wed, 30 Sep 2026 12:00:48 GMT Subject: Re: [PATCH 1/7] meson: avoid recompiling HTTP sources several times Message-ID: In-Reply-To: <20260924-pks-meson-improvements-v1-1-90b7f79f1c4e@pks.im> Patrick Steinhardt writes: > We only link curl into a subset of our subcommands. Consequently, as > both "http.c" and "http-walker.c" depend on curl, we don't compile these > into "libgit.a" but instead only link those into the commands that > depend on curl. > > In Meson, we wire these dependencies into the target executables by > using the `sources:` keyword. But this has the consequence that we're > recompiling those multiple several times, once for every different > command they are linked into. In fact, each of these sources is compiled > seven times, which of course has an impact on compilation speed. > > Fix this issue by instead linking these into a static library so that > they only need to be compiled once. This gives us an almost 10% speedup > in a clean build: > > Benchmark 1: meson compile (version = HEAD~) > Time (mean ± σ): 6.781 s ± 0.052 s [User: 100.775 s, System: 22.954 s] > Range (min … max): 6.709 s … 6.867 s 10 runs > > Benchmark 2: meson compile (version = HEAD) > Time (mean ± σ): 6.274 s ± 0.021 s [User: 91.882 s, System: 22.092 s] > Range (min … max): 6.242 s … 6.306 s 10 runs > > Summary > meson compile (version = HEAD) ran > 1.08 ± 0.01 times faster than meson compile (version = HEAD~) > > Signed-off-by: Patrick Steinhardt > --- > meson.build | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/meson.build b/meson.build > index 0a95d90d21..4fdb4c5405 100644 > --- a/meson.build > +++ b/meson.build > @@ -1925,10 +1925,13 @@ bin_wrappers += executable('scalar', > > if curl.found() > libgit_curl = declare_dependency( > - sources: [ > - 'http.c', > - 'http-walker.c', > - ], > + link_with: static_library('git-curl', > + sources: [ > + 'http.c', > + 'http-walker.c', > + ], > + dependencies: [libgit_commonmain, curl], > + ), So there are 7 locations which mark `libgit_curl` as a dependency, earlier this would have recompiled the two sources here each time for each of the 7 locations. Now we build a static library and declare the dependency to be linked with the static library. Looks good. > dependencies: [libgit_commonmain, curl], > ) > > > -- > 2.56.0.rc2.329.gd58861e689.dirty