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

[clang][deps] Generate command lines lazily #65691

Merged
merged 1 commit into from
Sep 8, 2023

Conversation

jansvoboda11
Copy link
Contributor

This patch makes the generation of command lines for modular dependencies lazy/on-demand. That operation is somewhat expensive and prior to this patch used to be performed multiple times for the identical ModuleDeps (i.e. when they were imported from multiple different TUs).

@@ -532,7 +539,8 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
// Finish the compiler invocation. Requires dependencies and the context hash.
MDC.addOutputPaths(CI, MD);

MD.BuildArguments = CI.getCC1CommandLine();
MD.BuildInvocationOrArguments =
std::make_unique<CowCompilerInvocation>(std::move(CI));
Copy link
Collaborator

Choose a reason for hiding this comment

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

You have shared_ptr but call make_unique; it works but seems unexpected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I'll align it with whatever pointer/value type we decide to go with.

Comment on lines 148 to 149
std::variant<std::shared_ptr<CowCompilerInvocation>, std::vector<std::string>>
BuildInvocationOrArguments;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The size of ModuleDeps used to be 200B. Storing CowCompilerInvocation directly would increase that to 360B, while just pointing to it keeps it at 208B. WDYT about the trade-offs?

Also, this should semantically be std::unique_ptr, since we're not sharing the ownership. But I'm not a fan of the move-only semantics that implies. I could wrap it in a unique-ptr-like type that's copyable?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, this should semantically be std::unique_ptr, since we're not sharing the ownership. But I'm not a fan of the move-only semantics that implies. I could wrap it in a unique-ptr-like type that's copyable?

Not sure I understand this - if you copy it you spend the same storage as if it was inlined, so it seems like either you want shared_ptr or inline storage.

I think shared_ptr is reasonable so this can be easily copied around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern is that if I use std::shared_ptr<CowCompilerInvocation>, ModuleDeps stops having value semantics. I guess that would be solved by making it a std::shared_ptr<const CowCompilerInvocation> to prevent mutation of the invocation.

Yes, both inlined and indirect storage use the same amount of storage (+- 8B), but I was thinking about this from memory locality perspective (storing the rarely used invocation away from frequently used data). But I guess this data structure is full of pointers to heap anyways, so that doesn't really matter.

I guess I'll just go with the inline approach to save on boilerplate.

@jansvoboda11 jansvoboda11 merged commit 3b1a686 into llvm:main Sep 8, 2023
1 of 2 checks passed
@jansvoboda11 jansvoboda11 deleted the lazy-command-line-gen branch September 8, 2023 00:45
jansvoboda11 added a commit to apple/llvm-project that referenced this pull request Sep 12, 2023
This patch makes the generation of command lines for modular
dependencies lazy/on-demand. That operation is somewhat expensive and
prior to this patch used to be performed multiple times for the
identical `ModuleDeps` (i.e. when they were imported from multiple
different TUs).
jansvoboda11 added a commit to apple/llvm-project that referenced this pull request Oct 5, 2023
This patch makes the generation of command lines for modular
dependencies lazy/on-demand. That operation is somewhat expensive and
prior to this patch used to be performed multiple times for the
identical `ModuleDeps` (i.e. when they were imported from multiple
different TUs).
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.

None yet

2 participants