TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Don't Optimize Your Includes

2 pointsby bubblehack3rover 1 year ago

2 comments

rewmieover 1 year ago
What an awfully ignorant and clueless blog post. From the article:<p>&gt; What, exactly, is the point of &quot;optimizing&quot; your source files to only &quot;include what you use&quot; if it makes compile times 50% worse on average? It&#x27;s frustrating that nobody seems to have put this central assumption of IWYU to the test. But I don&#x27;t think it&#x27;s all bad news.<p>The Include What You Use tool does not optimize anything. It fixes blatant mistakes in your project where source files lack the necessary include files they need to compile. Without these includes, your project only compiles by coincidence, because it relies on a very specific compilation and include order to indirectly define or forward-declare symbols your program needs to be able to compile.<p>When you include headers, your translation units will tend to grow, and the larger they grow the more code the compiler needs to go through to actually compile a translation unit.<p>Tools like Include What You Use should not be run in isolation. After you run them, your code will be able to compile regardless of the include order and compilation order, but some of these includes should be possible to get rid of by replacing them with forward-declararions or leverage other techniques such as PIMPLs.<p>Finally, if your compilation times bother you, you can always onboard your project to a compiler cache tool.
lbertover 1 year ago
I think you are misusing the PCH feature, in my opinion you are _supposed_ to include the code you depend on in the PCH: STL, QT and the likes and nothing of your of the project code, those libraries will almost never change in your project (and you surely want to rebuild everything when that happens) and in most cases they are the slowest to build.<p>In this case, compilation time of the PCH won&#x27;t matter much because it will happen very rarely.<p>After importing all of that stuff regardless of your use of it, include all internal projects normally and using IWYU on those is actually a good idea, as said by rewmie, to reduce bugs.<p>An other way might be to try to use header units or C++20 modules if you can (afaik QT doesn&#x27;t support them)