Skip to content

Commit

Permalink
Merge #6039: fix: optimize compilation time of gsl library
Browse files Browse the repository at this point in the history
dc59cbc fix: optimize includes in gsl/pointer.h to speed up compile time (Konstantin Akimov)
d5e32e1 fix: disable gsl iostream feature for faster compile time (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  This header `gsl/pointers.h` is included in multiple other headers all over codebase.
  Any extra line of code inside gsl/pointers.h makes all project to compile slower.

  ## What was done?
  Removed headers `<algorithm>`, `<system_error>`, `<iosfwd>` from gsl/pointers.h

  ## How Has This Been Tested?
  Run command 5 times, takes minimum time:

  - baseline
  ```
  $ time g++ -o /tmp/a.out gsl/pointers.h -O2 -g -I.
  real    0m0,572s
  user    0m0,461s
  sys     0m0,108s
  ```

   - removed algorithm:
  ```
  $ time g++ -o /tmp/a.out gsl/pointers.h -O2 -g -I.
  real    0m0,505s
  user    0m0,398s
  sys     0m0,107s
  ```

   - removed algorithm and system_error:
  ```
  real    0m0,332s
  user    0m0,265s
  sys     0m0,067s
  ```

   - disabled iostream:
  ```
  $ time g++ -o /tmp/a.out gsl/pointers.h -O2 -g -I. -D GSL_NO_IOSTREAMS
  real    0m0,316s
  user    0m0,256s
  sys     0m0,060s
  ```

  as a result, overall project compilation time is also improved: `make clean ; sleep 3s ; time make -j20`
  ```
  real    5m42,934s
  user    80m35,127s
  sys     6m40,735s
  ```
  ```
  real    5m28,862s
  user    75m31,931s
  sys     6m32,591s
  ```

  ## Breaking Changes
  N/A

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

ACKs for top commit:
  UdjinM6:
    utACK dc59cbc

Tree-SHA512: 353d79c0e297c92e823972b53daaaed42494554ce550ea800ce8aa6990c704cedfbcb922e1d735eb8fc01ad14ffa873d86cdbc4d3731d841496392bb74286d33
  • Loading branch information
PastaPastaPasta committed Aug 29, 2024
2 parents a40802b + dc59cbc commit 8d3f313
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ CXXFLAGS="$TEMP_CXXFLAGS"

fi

CPPFLAGS="$CPPFLAGS -DHAVE_BUILD_INFO"
CPPFLAGS="$CPPFLAGS -DHAVE_BUILD_INFO -DGSL_NO_IOSTREAMS"

AC_ARG_WITH([utils],
[AS_HELP_STRING([--with-utils],
Expand Down
6 changes: 2 additions & 4 deletions src/gsl/pointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
#include <gsl/assert.h> // for Ensures, Expects
#include <source_location.h>

#include <algorithm> // for forward
#include <cstddef> // for ptrdiff_t, nullptr_t, size_t
#include <memory> // for shared_ptr, unique_ptr
#include <system_error> // for hash
#include <memory> // for shared_ptr, unique_ptr, hash
#include <type_traits> // for enable_if_t, is_convertible, is_assignable
#include <utility> // for declval
#include <utility> // for declval, forward

#if !defined(GSL_NO_IOSTREAMS)
#include <iosfwd> // for ostream
Expand Down

0 comments on commit 8d3f313

Please sign in to comment.