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

Faster type activation #107

Open
3 of 4 tasks
ghost opened this issue Dec 22, 2015 · 3 comments
Open
3 of 4 tasks

Faster type activation #107

ghost opened this issue Dec 22, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Dec 22, 2015

As per #104, we should probably have a way of quickly creating types with given arguments. Relying on Activator.CreateInstance is okay, but we can do better.

  • Chalk up an API for consumption
  • Implement
  • Unit Tests
  • Performance Testing

Proposed API:

    class Activate
    {
        public static object Type(TypeInfo serviceType) => Type(serviceType, _emptyObjectArray);
        public static object Type(TypeInfo serviceType, object arg1) => Type(serviceType, new[] { arg1 });
        public static object Type(TypeInfo serviceType, object arg1, object arg2) => Type(serviceType, new[] { arg1, arg2 });
        public static object Type(TypeInfo serviceType, object arg1, object arg2, object arg3) => Type(serviceType, new[] { arg1, arg2, arg3 });
        public static object Type(TypeInfo serviceType, object arg1, object arg2, object arg3, object arg4) => Type(serviceType, new[] { arg1, arg2, arg3, arg4 });
        public static object Type(TypeInfo serviceType, object[] args) => null;
    }

This would cover the current use cases of Compose. However, there might be need for a generic API in the future, this will be covered as an extension to this API in the future.

@ghost ghost added the enhancement label Dec 22, 2015
@ghost ghost self-assigned this Dec 22, 2015
@ghost ghost added this to the later milestone Dec 22, 2015
@smudge202 smudge202 modified the milestones: 1.0.1-beta, later Dec 23, 2015
@ghost
Copy link
Author

ghost commented Dec 23, 2015

I've updated to reflect the currently implemented API. Added a load of basic tests to ensure that it works. Will need to add a lot more to cover things like generics etc, but I should imagine that they will be fine.

Think @danielcirket was interested in some performance stuff? He has some numbers from local benchmarking that will be shared at somepoint. My local tests seem to indicate that the current implementation is faster from a cold start. I still need to think about the use of the concurrent dictionary inside the current implementation also.

WIP Branch

@danielcirket
Copy link
Collaborator

https://github.com/sblackler/compose/pull/1 - Added some basic benchmarks for you @sblackler, super crappy way of doing it, need a better way of doing it to get the output etc, but at least gives an idea of the perf differences so far!

Done the PR to your WIP branch for now, but feel it should be mentioned here too.

@danielcirket
Copy link
Collaborator

Initial results from my machine (Times in milliseconds with 10k iterations):

new - Single Params | Min: 0 | Max: 0.6439 | Avg: 0.000204689999999994
new - No Params | Min: 0 | Max: 0.0885 | Avg: 0.000119879999999995
new - Multiple Params | Min: 0 | Max: 0.0147 | Avg: 0.000112559999999995

Activator - No Params | Min: 0 | Max: 0.0789 | Avg: 0.000201419999999988
Activator - Single Params | Min: 0.0009 | Max: 5.6403 | Avg: 0.00243510000000057
Activator - Multiple Params | Min: 0.0012 | Max: 0.8929 | Avg: 0.00159365000000024

Activate - No Params | Min: 0 | Max: 0.0153 | Avg: 0.00024144000000001
Activate - Single Params | Min: 0.0003 | Max: 0.2388 | Avg: 0.000391410000000064
Activate - Multiple Params | Min: 0.0003 | Max: 0.0472 | Avg: 0.000494850000000075

@ghost ghost mentioned this issue Dec 26, 2015
2 tasks
@ghost ghost removed their assignment May 11, 2016
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

2 participants