Skip to content
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

Compile CalcManager project with or without precompiled headers #436

Merged
merged 12 commits into from
Apr 18, 2019

Conversation

danbelcher-MSFT
Copy link

Fixes #324 .

Description of the changes:

In an effort to support other compilers (#109), this change reworks how precompiled headers are handled. For toolchains where precompiled headers are not used, there is unnecessary compilation cost because each source file explicity includes the pch, meaning all system headers in the pch were recompiled for each translation unit. This change modifies the project's files so that each translation unit includes a minimal set of dependent headers. For MSVC users, the precompiled headers option is still enabled and the precompiled header is added to each translation unit using the compiler's Forced Includes option. The end result is that MSVC users still see the same build times, but other toolchains are free to use or not use precompiled headers.

Risks introduced

Given that our CI build uses MSVC, this change introduces the risk that a system header is added to the pch and the CalcManager project builds correctly, but builds could be broken for other toolsets that don't use pch. We know we want to add support for Clang in our CI build (#211). It seems reasonable to also compile without precompiled headers there so that we can regression test this setup.

How changes were validated:

  1. Rebuild CalcManager project. Compile time: ~4.5s.
  2. Disable precompiled headers, keeping explicit include for pch in each source file. Compile time: ~13s.
  3. Remove explicit pch inclusion and add the appropriate headers to each translation unit to allow the project to compile. Compile time: ~8s.
  4. Re-enable pch and include it using the Forced Includes compiler option. MSVC compile time: ~4.5s.

Minor changes

  • Delete 'targetver.h'. I found this while looking around for system headers in the project. It's unused and unreferenced so let's remove it.

mcooley
mcooley previously approved these changes Apr 4, 2019
CONTRIBUTING.md Outdated Show resolved Hide resolved
@janisozaur
Copy link
Contributor

This is great! I'll check GCC and clang builds and leave my review at some point today. Many thanks for implementing my idea.

Copy link
Contributor

@janisozaur janisozaur left a comment

Choose a reason for hiding this comment

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

ExpressionCommandInterface.h is not part of the diff, hence I can't comment there, but:

diff --git a/src/CalcManager/ExpressionCommandInterface.h b/src/CalcManager/ExpressionCommandInterface.h
index ce89dd8..cc80745 100644
--- a/src/CalcManager/ExpressionCommandInterface.h
+++ b/src/CalcManager/ExpressionCommandInterface.h
@@ -4,6 +4,7 @@
 #pragma once
 #include "CalculatorVector.h"
 #include "Command.h"
+#include <memory> // for std::shared_ptr
 
 class ISerializeCommandVisitor;
 

src/CalcManager/CalculatorManager.cpp Show resolved Hide resolved
src/CalcManager/CalculatorVector.h Show resolved Hide resolved
src/CalcManager/Ratpack/basex.cpp Show resolved Hide resolved
src/CalcManager/Ratpack/conv.cpp Show resolved Hide resolved
src/CalcManager/Ratpack/num.cpp Show resolved Hide resolved
src/CalcManager/Ratpack/ratpak.h Show resolved Hide resolved
src/CalcManager/Ratpack/support.cpp Show resolved Hide resolved
src/CalcManager/UnitConverter.cpp Show resolved Hide resolved
src/CalcManager/UnitConverter.h Show resolved Hide resolved
@danbelcher-MSFT
Copy link
Author

@janisozaur, how are you identifying these extra header dependencies? I rebased my branch on top of #211 and I was able to build with CMake/Clang with no problems.

@janisozaur
Copy link
Contributor

GCC/libstdc++ and lots of time spent on writing code for the trinity of compilers.

@danbelcher-MSFT
Copy link
Author

I see. I don't have GCC set up so I can't verify your changes right now. I'll have to trust you :)
I do have a question.. For example, in UnitConverter.h, you suggested to add <memory> because the header uses std::shared_ptr. You didn't suggest <string> even though the header uses std::wstring. Why the discrepancy?

@danbelcher-MSFT
Copy link
Author

danbelcher-MSFT commented Apr 5, 2019

Second suggestion.. How do you feel about taking this change so we can unblock #211, then we can add onto it to support GCC?

@janisozaur
Copy link
Contributor

It must've been transitively included via other file. I don't claim this is exhaustive, but it works in my case. Of you find any more missing headers, I'd suggest you include them. I might spend more time on that in the future.

It's not really blocking #211 in my opinion, but I can see how having this merged first would lead to having nicer history.

@janisozaur
Copy link
Contributor

Actually, #211 seems to do away with some headers. It might actually be required for this to go in first (with comments addressed) or #211 to add some includes.

@grochocki grochocki added codebase quality Issues that are not bugs, but still might be worth improving (eg, code hygiene or maintainability) and removed codebase quality Issues that are not bugs, but still might be worth improving (eg, code hygiene or maintainability) labels Apr 7, 2019
@danbelcher-MSFT
Copy link
Author

@janisozaur, can you take a second look? I tried requesting your review again through GitHub but the 'refresh' button doesn't seem to be working for me right now. Sorry if I spammed you with notifications!

@mcooley, I need your review so I can merge.

@janisozaur
Copy link
Contributor

Sure, I'll re-review.

@danbelcher-MSFT
Copy link
Author

@janisozaur, I'm ready to merge this change now. I took your suggestions without a way to validate with GCC. If you find that I broke something, feel free to comment on this PR or supply a fix.

@danbelcher-MSFT danbelcher-MSFT merged commit d21a47d into microsoft:master Apr 18, 2019
@danbelcher-MSFT danbelcher-MSFT deleted the dabelc/PchCleanup branch April 22, 2019 23:52
EriWong pushed a commit to EriWong/calculator that referenced this pull request Jun 5, 2019
…osoft#436)

Fixes microsoft#324 .

Description of the changes:
In an effort to support other compilers (microsoft#109), this change reworks how precompiled headers are handled. For toolchains where precompiled headers are not used, there is unnecessary compilation cost because each source file explicity includes the pch, meaning all system headers in the pch were recompiled for each translation unit. This change modifies the project's files so that each translation unit includes a minimal set of dependent headers. For MSVC users, the precompiled headers option is still enabled and the precompiled header is added to each translation unit using the compiler's Forced Includes option. The end result is that MSVC users still see the same build times, but other toolchains are free to use or not use precompiled headers.

Risks introduced
Given that our CI build uses MSVC, this change introduces the risk that a system header is added to the pch and the CalcManager project builds correctly, but builds could be broken for other toolsets that don't use pch. We know we want to add support for Clang in our CI build (microsoft#211). It seems reasonable to also compile without precompiled headers there so that we can regression test this setup.

How changes were validated:
Rebuild CalcManager project. Compile time: ~4.5s.
Disable precompiled headers, keeping explicit include for pch in each source file. Compile time: ~13s.
Remove explicit pch inclusion and add the appropriate headers to each translation unit to allow the project to compile. Compile time: ~8s.
Re-enable pch and include it using the Forced Includes compiler option. MSVC compile time: ~4.5s.
Minor changes
Delete 'targetver.h'. I found this while looking around for system headers in the project. It's unused and unreferenced so let's remove it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider reworking how PCHs are used
5 participants