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

[Modules] Increased build times across translation units in O0 #61064

Closed
koplas opened this issue Feb 28, 2023 · 6 comments
Closed

[Modules] Increased build times across translation units in O0 #61064

koplas opened this issue Feb 28, 2023 · 6 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules slow-compile

Comments

@koplas
Copy link

koplas commented Feb 28, 2023

Given the following translation units:

export module a;

export namespace a {
    int a_0() {return 0;}
    int a_1() {return 0;}
    int a_2() {return 0;}
...
    int a_1000000() {return 0;}
}
export module b;
import a;

export namespace b {
    int b() {
        return 1;
    }
}
export module c;
import b;

export namespace c {
    int c() {
        return b::b();
    }
}

And running the following:

echo "Building a.cppm"
time clang++ -std=c++20 --precompile a.cppm -o a.pcm
time clang++ -std=c++20 a.cppm -c -o a.o
echo "Building b.cppm"
time clang++ -std=c++20 -fprebuilt-module-path=. --precompile b.cppm -o b.pcm
time clang++ -std=c++20 -fprebuilt-module-path=. b.cppm -c -o b.o
echo "Building c.cppm"
time clang++ -std=c++20 -fprebuilt-module-path=. --precompile c.cppm -o c.pcm
time clang++ -std=c++20 -fprebuilt-module-path=. c.cppm -c -o c.o

Results in this output:

Building a.cppm

real    0m25,961s
user    0m24,515s
sys     0m1,337s

real    1m23,304s
user    1m20,309s
sys     0m2,856s

Building b.cppm

real    0m2,201s
user    0m1,978s
sys     0m0,220s

real    0m5,779s
user    0m5,373s
sys     0m0,400s

Building c.cppm

real    0m2,146s
user    0m1,957s
sys     0m0,187s

real    0m5,714s
user    0m5,317s
sys     0m0,389s

As expected the build times of a.cppm is high. However, even the build of c.cppm takes a lot of time.
Note that in the pre-compiling phase of b.cppm and c.cppm circa 200 ms is spent in WriteAst, despite not having many lines of code.

build-times-test.zip

@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules and removed new issue labels Feb 28, 2023
@llvmbot
Copy link
Member

llvmbot commented Feb 28, 2023

@llvm/issue-subscribers-clang-modules

@ChuanqiXu9
Copy link
Member

This should be duplicated with #60996

@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Mar 2, 2023
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Mar 2, 2023
@ChuanqiXu9 ChuanqiXu9 changed the title [Modules] Increased build times across translation units [Modules] Increased build times across translation units in O0 Mar 2, 2023
@ChuanqiXu9 ChuanqiXu9 removed the duplicate Resolved as duplicate label Mar 2, 2023
@ChuanqiXu9
Copy link
Member

Oh, sorry. This is not duplicated with #60996 since that issues focus on the optimization mode and this issue is not related to optimizations.

@ChuanqiXu9 ChuanqiXu9 reopened this Mar 2, 2023
@ChuanqiXu9
Copy link
Member

Here are more profiled information for this: https://discourse.llvm.org/t/modules-increased-build-times/68755/6

@koplas
Copy link
Author

koplas commented Mar 2, 2023

My bad, I should have been more explicit.

@ChuanqiXu9
Copy link
Member

ChuanqiXu9 commented Mar 10, 2023

@koplas Now b and c should compile quickly (less than 0.1s) after the above patch.

I expected this can produce a strong impact on modular codes. However, in a realworld local modularized project, I only found this patch can produce 3% improvements. It makes sense in some level since the reproducer is in the very edging case. Could you help to test clang again in your project and share the profile results in the above link? Thanks in advance.

CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this issue Mar 17, 2023
Close llvm/llvm-project#61064.

The root cause of the issue is that we will deserilize some declarations
eagerly when reading the BMI. However, many declarations in the BMI are
not necessary for the importer. So it wastes a lot of time.
ChuanqiXu9 added a commit that referenced this issue Apr 6, 2023
…odules

Close #61064.

The root cause of the issue is that we will deserilize some declarations
eagerly when reading the BMI. However, many declarations in the BMI are
not necessary for the importer. So it wastes a lot of time.

The new commit handles the MSVC's extension #pragma comment and #pragma
detect_mismatch to follow MSVC's behavior. See pr61783 for details.
gysit pushed a commit to nextsilicon/llvm-project that referenced this issue Apr 27, 2023
…odules

Close llvm#61064.

The root cause of the issue is that we will deserilize some declarations
eagerly when reading the BMI. However, many declarations in the BMI are
not necessary for the importer. So it wastes a lot of time.

The new commit handles the MSVC's extension #pragma comment and #pragma
detect_mismatch to follow MSVC's behavior. See pr61783 for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules slow-compile
Projects
None yet
Development

No branches or pull requests

4 participants