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

Resolution root bound dependency expression de-duplication #11

Closed
dadhi opened this issue Aug 23, 2018 · 2 comments
Closed

Resolution root bound dependency expression de-duplication #11

dadhi opened this issue Aug 23, 2018 · 2 comments

Comments

@dadhi
Copy link
Owner

dadhi commented Aug 23, 2018

In V3 I have removed Expression level cache stored once per Factory. This simlified a problem with condition based resolution, and removed a whole lot of adhoc checks.

Problem

  • This also introduced a problem of possibly multiple equivalent but not the same dependency expressions. In case when expression is or contains a lambda, the lambda will be compiled to different multiple delegates by FEC
  • Increased the size of result expession if it contains equivalent sub-expressions.

Solution

Memoize the built dependency expression into resolution root Request by the FactoryId. Exluding wrappers. Use the memoized expression instead of building a new one.
For open-generics we will use id of closed factory.

It is not a cache, cause it will be dropped when result expression is build and compiled.
This is similar to storing expression in a local var and using this var multiple times to build the result.

@dadhi
Copy link
Owner Author

dadhi commented Aug 23, 2018

Should improve #1 by faster compilation and tiny bit faster resolution, and less memory consumption. Because scoped service expression contains nested lambda.

@dadhi
Copy link
Owner Author

dadhi commented Aug 27, 2018

Here is the benchmark of duplicated (multiple) vs. de-duplicated (shared) nested lambda.
The sample expression is: () => new A(() => new X(new Y()), new B(() => new X(new Y()))) where
() => new X(new Y()) is duplicate: 5% faster and less memory too.

image

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

No branches or pull requests

1 participant