Skip to content

Remove unnecessary includes #6060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2021
Merged

Conversation

tautschnig
Copy link
Collaborator

@tautschnig tautschnig commented Apr 27, 2021

Manual removal of includes based on include-what-you-use's output,
filtered for includes that should be removed.

A fully automated use of include-what-you-use doesn't seem feasible at this time for there are a number of false positives of includes that iwyu claims can be safely removed.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig self-assigned this Apr 27, 2021
@codecov
Copy link

codecov bot commented Apr 27, 2021

Codecov Report

Merging #6060 (450845d) into develop (1f0d7b3) will increase coverage by 0.21%.
The diff coverage is 94.73%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6060      +/-   ##
===========================================
+ Coverage    74.17%   74.39%   +0.21%     
===========================================
  Files         1446     1447       +1     
  Lines       157784   157787       +3     
===========================================
+ Hits        117036   117383     +347     
+ Misses       40748    40404     -344     
Impacted Files Coverage Δ
jbmc/src/janalyzer/janalyzer_main.cpp 100.00% <ø> (ø)
jbmc/src/java_bytecode/assignments_from_json.cpp 97.26% <ø> (ø)
jbmc/src/java_bytecode/ci_lazy_methods.cpp 99.47% <ø> (ø)
jbmc/src/java_bytecode/ci_lazy_methods.h 100.00% <ø> (ø)
jbmc/src/java_bytecode/ci_lazy_methods_needed.cpp 98.24% <ø> (ø)
jbmc/src/java_bytecode/ci_lazy_methods_needed.h 100.00% <ø> (ø)
jbmc/src/java_bytecode/convert_java_nondet.cpp 81.15% <ø> (ø)
...java_bytecode/create_array_with_type_intrinsic.cpp 97.67% <ø> (ø)
jbmc/src/java_bytecode/expr2java.cpp 86.61% <ø> (ø)
jbmc/src/java_bytecode/expr2java.h 100.00% <ø> (ø)
... and 705 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56adbb2...450845d. Read the comment docs.

@tautschnig tautschnig force-pushed the includes-cleanup branch 16 times, most recently from 54d6fc8 to d524f42 Compare May 1, 2021 19:40
@tautschnig tautschnig removed their assignment May 1, 2021
@tautschnig tautschnig marked this pull request as ready for review May 1, 2021 19:42
@tautschnig tautschnig assigned martin-cs and unassigned kroening May 1, 2021
@tautschnig tautschnig force-pushed the includes-cleanup branch 2 times, most recently from 4b186f5 to 4e8601f Compare May 1, 2021 23:00
Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am really glad this PR exists and even more glad that wasn't the one to have to write it! I think it is definitely a good thing and should reduce build times. Do you have a rough number for how much time it saves? A few concerns:

  1. Not sure why the coverage metrics drop. Is it counting forward declarations of classes as executable code?
  2. This has a very "breaks all existing PRs" feel to it. What, if anything, are we going to do about that?
  3. Having gone to all of this trouble, is there anything we could add to the CI / review process to avoid accumulating unnecessary includes and forward declarations? Could we have some kind of 'try to remove #include lines from the PR and see if it still builds' task. If it build develop first and then just tried a loop of removing lines adding headers from the diff, applying and seeing if it still builds?

@@ -8,7 +8,9 @@ Author: Daniel Kroening, [email protected]

#include "gcc_message_handler.h"

#include <util/unicode.h>
#ifdef _MSC_VER
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be an idiom. Would it be better to have the ifdef guard in util/unicode.h?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's really just the use of widen (in most of those files) that's required with Visual Studio only. The header provides more functionality than that, so I don't think that's really an option.

@tautschnig
Copy link
Collaborator Author

I am really glad this PR exists and even more glad that wasn't the one to have to write it! I think it is definitely a good thing and should reduce build times. Do you have a rough number for how much time it saves? A few concerns:

I've now added data to the commit message. Builds seem approximately 7% faster.

1. Not sure why the coverage metrics drop.  Is it counting forward declarations of `class`es as executable code?

I have no idea, and the Codecov page doesn't seem to be working at the moment. It seems that quite often with code removal the coverage metrics appear to drop by a tiny fraction, which is weird.

2. This has a very "breaks all existing PRs" feel to it.  What, if anything, are we going to do about that?

Yes, there may be an impact on several PRs, but I don't expect that many actually: most of the includes simply weren't necessary, and when PRs change implementations only and not header files then most likely they're not impacted at all as an #include may have been shifted from the header file to the cpp file.

3. Having gone to all of this trouble, is there anything we could add to the CI / review process to avoid accumulating unnecessary includes and forward declarations?  Could we have some kind of 'try to remove #include lines from the PR and see if it still builds' task.  If it build develop first and then just tried a loop of removing lines adding headers from the diff, applying and seeing if it still builds?

I do think that we could use more recent versions of include-what-you-use in CI, perhaps 8.0 (which is in Ubuntu 20.04) is quite reasonable already. I've worked with 5.0 (from Ubuntu 18.04), which wasn't too great. The issue mainly is around detecting use of types in templates. I'll create a separate PR to play with this (also need to figure out how long it takes to run).

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow - thats a lot of work... 👍

tautschnig added 2 commits May 6, 2021 20:39
Manual removal of includes based on include-what-you-use's output,
filtered for includes that should be removed. The goal is to avoid
unnecessary build dependencies, reducing the amount of code that needs
to be rebuilt during incremental builds. The build time for fresh
rebuilds decreases by about 7% as the following experiment shows:

```
rm -rf build && ccache -C
cmake -H. -Bbuild -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -Wl,--threads"
/usr/bin/time -v ninja -C build -j32
```

Repeated execution for both develop and this branch producing the
following data, which less than 1s of variation across multiple runs:

develop:
```
  Command being timed: "ninja -C build -j32"
  User time (seconds): 2714.02
  System time (seconds): 203.75
  Percent of CPU this job got: 2833%
  Elapsed (wall clock) time (h:mm:ss or m:ss): 1:42.96
```

this PR:
```
  Command being timed: "ninja -C build -j32"
  User time (seconds): 2507.14
  System time (seconds): 189.95
  Percent of CPU this job got: 2822%
  Elapsed (wall clock) time (h:mm:ss or m:ss): 1:35.56
```
@tautschnig tautschnig merged commit 1ab5de1 into diffblue:develop May 7, 2021
@tautschnig tautschnig deleted the includes-cleanup branch May 7, 2021 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants