-
-
Notifications
You must be signed in to change notification settings - Fork 6
Is there a way we can lazy load interface mappings? #74
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
Comments
@JROBOTO public class Person : Human
{
public Human Human { get; set; }
}
public class Human
{
public bool IsAlive { get; set; }
} The generated code for the Human property is :
Which would be changed to support Lazy? |
Ok just had a deeper look and its not the actual properties but the TypeAdapterConfig being generated in each constructor that is causing it to be slow especially if a class has a lot of subclasses proxied. In my example. constructing each proxy takes about 4ms however for 15000 objects in total, that adds up |
I do not understand yet how to build this and if this is possible using mapster. As a possible quick fix, I've defined the mappings in a static constructor, so it's only executed once. public partial class PersonProxy : global::ProxyInterfaceSourceGeneratorTests.Source.HumanProxy, global::ProxyInterfaceSourceGeneratorTests.Source.IPerson
{
static PersonProxy()
{
Mapster.TypeAdapterConfig<global::ProxyInterfaceSourceGeneratorTests.Source.Human, global::ProxyInterfaceSourceGeneratorTests.Source.IHuman>.NewConfig().ConstructUsing(instance2145588841 => new global::ProxyInterfaceSourceGeneratorTests.Source.HumanProxy(instance2145588841));
Mapster.TypeAdapterConfig<global::ProxyInterfaceSourceGeneratorTests.Source.IHuman, global::ProxyInterfaceSourceGeneratorTests.Source.Human>.NewConfig().MapWith(proxy1567394325 => ((global::ProxyInterfaceSourceGeneratorTests.Source.HumanProxy) proxy1567394325)._Instance);
}
// . . . |
Fair enough, I'm not going to pretend to be an expert in Mapster, in fact my only interaction with it is through your library 😆 |
Not sure what policy you have on who you count as a reviewer on a PR but I have given it a tick |
I've create a new NuGet (0.3.0) which should be available shortly. Please test this one, and report back if this helps. |
That's given us an incredible amount of performance, thanks!!! |
Some of the objects we are attempting to map can be quite big however we rarely need every property of every bit. Would it be possible to adapt the functionality so that, internally, we only map the property of the instance to its interface if that interface is called upon? I have a function I am calling where the API takes 0.08 seconds however the resulting mapping takes ~1 minute for 12000 items in the resulting collection.
For example:
If I have object
If I had a function returning the mapped
IThing
, theSubThing
property would not be mapped until I explicitly asked for it.Purely hypothetical of course
The text was updated successfully, but these errors were encountered: