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

[SUGGESTION] Only include cpp2regex.h when @regex is used to improve compile time #1199

Closed
bluetarpmedia opened this issue Aug 1, 2024 · 6 comments · Fixed by #1219
Closed

Comments

@bluetarpmedia
Copy link
Contributor

The generated cpp2regex.h file is ~170 KB and so I wondered what the impact on compile times are.

With clang 18 on ubuntu, I tested with and without including cpp2regex.h from inside cpp2util.h when compiling an empty main function lowered from Cpp2:

//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



//=== Cpp2 type definitions and function declarations ===========================

[[nodiscard]] auto main() -> int;

//=== Cpp2 function definitions =================================================

[[nodiscard]] auto main() -> int{

    return 0; 
}

With cpp2regex.h

$ time clang++ -std=c++23 -stdlib=libc++ -fexperimental-library -Wall -Wextra -Wconversion source.cpp

real    0m2.628s
user    0m1.953s
sys     0m0.098s

Without cpp2regex.h

$ time clang++ -std=c++23 -stdlib=libc++ -fexperimental-library -Wall -Wextra -Wconversion source.cpp

real    0m1.138s
user    0m1.074s
sys     0m0.045s

I repeated the test a few times and the results were relatively stable. The real (wall clock) time is approx 2X more when bringing in cpp2regex.h, so I wondered if cppfront can detect whether it's needed and then conditionally include it?

@MaxSagebaum
Copy link
Contributor

This is a good point. Detecting this and adding the include could be an easy fix.

If this is not desired an other fix would be to split cpp2regex.h2 into two parts. The parsing part and the runtime part. Only the runtime part is actually required after applying @regex.

@bluetarpmedia
Copy link
Contributor Author

That's interesting... does that mean we could do both? Only conditionally include the runtime part for the lowered C++ code?

@hsutter
Copy link
Owner

hsutter commented Aug 5, 2024

an other fix would be to split cpp2regex.h2 into two parts. The parsing part and the runtime part. Only the runtime part is actually required after applying @regex.

When I was reviewing the PR I thought of this, but I didn't grok it well enough to know what parts are the metafunction-at-compile-time part and what part is the runtime-support-library part.

I think a good first step would be to move the metafunction-only parts right into reflect.h2.

@MaxSagebaum
Copy link
Contributor

I performed the split in #1219.

I also tried to add the functionality for adding the include on the fly. But my understanding of cppfront is too limited. Unlinke my MR for enabling metafunction to add code outside of the context (#809), this is not straight forward.

@hsutter Can you have look or give me some pointers on how to do this?
After such a change, adding the include should be something like t.add_include("#include \"cpp2regex.h2\""); in regex_gen.

@hsutter
Copy link
Owner

hsutter commented Aug 11, 2024

Circling back: This has now been fixed in #1219, thanks again @bluetarpmedia for pointing this out!

"Don't pay for what you don't use" FTW. 👍

@JohelEGP
Copy link
Contributor

JohelEGP commented Oct 3, 2024

I have seen the added includes_ members in the passing while rebasing my branches.
It seems like this can be generalized to work for uses of std:: names.
That could make -include-std redundant.
The pure2- regression tests would see their compile times improved,
and the mixed- regression tests wouldn't need explicit #includes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants