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

Compilation performance benchmark (boost::di vs kangaru) #79

Open
Dragnalith opened this issue Jan 8, 2019 · 5 comments
Open

Compilation performance benchmark (boost::di vs kangaru) #79

Dragnalith opened this issue Jan 8, 2019 · 5 comments

Comments

@Dragnalith
Copy link

Dragnalith commented Jan 8, 2019

I am investigation compilation performance, and I have discovered boost::di was way faster than kangaru.
Both have a compile time "autowire" feature. The following table compare boost::di with kangaru with and without autowire. I have generated a class graph and services are all kgr::single_service services.

Class Count Kangaru (autowire) Kangaru (dep) Boost::di
4 1.56s 1.23s 0.4s
11 3.27s 1.65s 0.74s
26 7.41s 2.26s 1.22s
57 19.93s 3.81s 2.11s
120 compiler is out of heap space 7.17s 4.13s

We can see Kangaru (autowire) seems to have an exponential complexity where for Boost::di it looks linear. This difference is surprising because even without autowire boost::di is faster. I am also surprise I cannot compile a graph with more than 100 classes.

I wonder which template black bagic makes this kind of performance difference. If we find it we could use it for kangaru's autowire.

You can find my test bench it this repository: https://github.com/Dragnalith/di_experiment. The dependency of this gen_test.h matched the 57 class count row.

@gracicot
Copy link
Owner

gracicot commented Jan 8, 2019

Thanks a lot for this. It was one of my task but didn't had the time yet (#73). I suspect service_map + ADL lookup is at fault for this.

I'll run your test with templight to see what's going on.

@Dragnalith
Copy link
Author

@gracicot Do you have any idea how to "profile" compilation? And any tips about how to understand what is going on under the hoop? I would like to help, I could allocate some time, but I feel complete lost in all these templates mecanisms.

@gracicot
Copy link
Owner

gracicot commented Jan 9, 2019

I never really profiled template code before, so the subject is quite new to me too. I know some guidelines (eg: aliases are lighter then instanciating types) but that's about it. I also discovered templight as a tool recently but the setup is tedious.

There's indeed a lot of template machinery in this library. Explore as you wish and if you're stuck, poke me on gitter. I'd be happy to help.

@gracicot
Copy link
Owner

@Dragnalith Hello! It's been a long time, and I thought about a solution for the autowire compilation time explosion: How about defining the service map inside the classes using friend function?

There are two ways to do this:

struct class_a_service;

struct class_a {
    friend auto service_map(class_a const&) -> class_a_service;
};

struct class_a_service : kgr::single_service<class_a, kgr::autowire> {};

And the second way:

struct class_a {
    friend auto service_map(class_a const&) -> kgr::autowire_single;
};

Would it be possible for you to run your tests again using these patterns instead?

My hypothesis is that it will significantly reduce the compile times, probably reduce the time complexity because a new service don't add a possible overload for other service to see.

@selat
Copy link

selat commented Jul 28, 2019

You can profile compilation time with latest clang built from master. Recently they added new option-ftime-trace which generates tracing profile for compiler execution. More details can be found in this blog post: https://aras-p.info/blog/2019/01/16/time-trace-timeline-flame-chart-profiler-for-Clang/

Heavy template usage usually looks like this o_O

image

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

No branches or pull requests

3 participants