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

Improve code generation #83

Merged
merged 3 commits into from
Apr 14, 2024
Merged

Improve code generation #83

merged 3 commits into from
Apr 14, 2024

Conversation

mingxwa
Copy link
Collaborator

@mingxwa mingxwa commented Apr 11, 2024

Avoid generating duplicated code for trivially-copyable, -relocatable, -destructible pointer types. Although link-time optimizations may help, it is always more efficient to avoid duplication from the front-end.

Before (link):

image

After (link)

image

We can also observe significant performance boost at link-time. I tried to compile the following code on my dev machine with MSVC (with linker option /OPT:ICF to avoid generating duplicated code):

#include <proxy/proxy.h>

namespace spec {

PRO_DEF_FACADE(Any, std::tuple<>, pro::copyable_ptr_constraints);

}  // namespace spec

void DoSomethingWithAny(pro::proxy<spec::Any>);

template <std::size_t... Is>
void TestImpl(std::index_sequence<Is...>) {
  (DoSomethingWithAny(pro::make_proxy<spec::Any, std::integral_constant<std::size_t, Is>>()), ...);
}
template <std::size_t N>
void Test() {
  TestImpl(std::make_index_sequence<N>{});
}

int main() {
  Test<1000>();
}

Before this change, compiling it took 6.0 seconds; linking it took with an empty implementation of DoSomethingWithAny() took 7.3 seconds. After this change, compiling it took almost the same time, but linking it with the same implementation of DoSomethingWithAny() only took 1.7 seconds.

Closes #82

@mingxwa mingxwa requested review from tian-lt and guominrui April 11, 2024 10:46
@mingxwa mingxwa marked this pull request as ready for review April 11, 2024 10:47
@mingxwa mingxwa merged commit e650e70 into microsoft:main Apr 14, 2024
4 checks passed
@mingxwa mingxwa deleted the user/mingxwa/qoi branch April 14, 2024 15:18
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.

QoI: Avoid generating duplicated code for special pointer types
3 participants