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

Reduce the symbol load caused by feature templates #41

Merged
merged 9 commits into from
May 7, 2020

Conversation

chapulina
Copy link
Contributor

@chapulina chapulina commented Apr 20, 2020

Reopening the pull request with @mxgrey 's work.

Resolves #28.


Original description

This PR should greatly reduce the size and quantity of symbols that get generated by templates, likely by some orders of magnitude. It should also help make the size and quantity of symbols scale much much better (should be nearly constant [size] and linear [quantity] respectively now instead of linear [size] and squared [quantity]).

I believe this has been the leading cause of slow compilation times, especially for GCC.

I made a simple program here that instantiates every entity type with every existing feature in ign-physics, and using all headers provided by ign-physics. Before this PR, using gcc-8 it spent over an hour trying to compile on my XPS15 with no success. After this PR, using gcc-8 it compiles in just under 30 seconds. Clang is significantly better, compiling in 11 seconds after this PR.

There is still some cleanup to do, but I wanted to open this PR so the compilation times of ign-gazebo can be tested against it.

@chapulina chapulina requested review from mxgrey and scpeters April 20, 2020 23:06
@chapulina chapulina self-assigned this Apr 20, 2020
@chapulina chapulina linked an issue Apr 20, 2020 that may be closed by this pull request
Copy link
Contributor Author

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

+1, this works for me and I couldn't spot anything weird - although I should mention that I don't fully understand the entire code.

Let's wait for @scpeters 's review.

@chapulina chapulina added 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome labels May 4, 2020
@scpeters
Copy link
Member

scpeters commented May 4, 2020

I don't understand the template stuff. I don't know if @azeey has a better handle on that.

It would be nice to add the example program from https://github.com/mxgrey/test_ign_physics to either the examples folder or as a performance test

@mxgrey
Copy link
Contributor

mxgrey commented May 5, 2020

We could add that as a test to this repo, although the point of it is to make the most excruciating compilation time possible. I don't think it would be a good idea to add it to the all target or even a tests target. If it gets added, it should be its own standalone target that nothing else depends on.

Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Looks good to me! The reduction in compile time is ridiculous 🎉 . From what I can tell, this still checks for duplicate Features, but I remember you mentioned that in order to reduce compile times, we have to assume that there are no duplicate Features in a FeatureList. Is that still the case?

Also, I see that the DeterminePlugin template uses ComposePlugin, which looks similar to Aggregate in the way it iterates through Features. Can ComposePlugin be updated to work like the new ExtractAPI? Would that save any more compile time?

public: template<typename... T>
class type : public virtual
Aggregate<Selector, FeatureListT>::template type<T...> { };
template <typename FeatureTuple, typename... T>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the Aggregate template be removed now that ExtractAPI doesn't use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, @azeey ! I'll go ahead and merge this PR to unblock ign-gazebo, but @mxgrey , feel free to follow up in a subsequent PR if needed.

Copy link
Contributor

@mxgrey mxgrey May 8, 2020

Choose a reason for hiding this comment

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

From what I can tell, this still checks for duplicate Features, but I remember you mentioned that in order to reduce compile times, we have to assume that there are no duplicate Features in a FeatureList. Is that still the case?

That is not the case, fortunately! There should be no problem at all with having duplicate features.

Can ComposePlugin be updated to work like the new ExtractAPI? Would that save any more compile time?

I considered that, but I didn't have enough time to really explore it. When I inspect the symbols that get generated, there are relatively few symbols related to ComposePlugin, most likely because all entity types for the same set of features share the same plugin type, so cutting down on ComposePlugin probably won't offer much. It's certainly worth trying if someone has cycles to spare.

Can the Aggregate template be removed now that ExtractAPI doesn't use it?

For some reason I thought Aggregate was still being used somewhere, but I can no longer find wherever I thought it was being used. So sure, I guess we can throw it out now.

@chapulina chapulina merged commit 6e96306 into ign-physics2 May 7, 2020
@chapulina chapulina deleted the reduce_symbols branch May 7, 2020 14:25
@azeey
Copy link
Contributor

azeey commented May 7, 2020

Can this be backported to ign-physics1? It looks like the compile times there are also getting worse.

@scpeters
Copy link
Member

scpeters commented May 7, 2020

Can this be backported to ign-physics1? It looks like the compile times there are also getting worse.

I'm willing to review a pull request; I'm not sure if it will cause a problem with API/ABI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel 🔮 dome Ignition Dome
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reopen pull request to reduce symbol load
4 participants