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

Infinite time to map highly bound classes #111

Closed
alexeyosipov opened this issue May 3, 2017 · 12 comments
Closed

Infinite time to map highly bound classes #111

alexeyosipov opened this issue May 3, 2017 · 12 comments

Comments

@alexeyosipov
Copy link

alexeyosipov commented May 3, 2017

I have several highly-connected classes in my project. At this picture you may see types(vertexes) and properties(edges) of it:
image

Looks like due to some caching problems mapster maps any class of this diagram almost infinitely long. I can provide these classes if you need in.

@chaowlert
Copy link
Collaborator

Mapster will recursively traverse to all members and create new objects. And if there is circular relationship, mapping will take forever until you got stack overflow exception.

To prevent object to be recursively mapped, pls use PreserveReference (https://github.com/eswann/Mapster#PreserveReference)

@alexeyosipov
Copy link
Author

alexeyosipov commented May 10, 2017

@chaowlert it doesn't help. I've set this option and it still get stuck. I can provide an example project.

@chaowlert chaowlert reopened this May 10, 2017
@alexeyosipov
Copy link
Author

... or even PR with unit test if needed

@chaowlert
Copy link
Collaborator

PR is always welcome! Do you have any clue what causes the problem?

@alexeyosipov
Copy link
Author

alexeyosipov commented May 15, 2017

@chaowlert I think it is somehow connected to the way mapster caches already mapped classes, I added a counter in the code and it showed me that most of my classes are scanned thousands of times. May be am just setting up things incorrectly, so you may correct me after looking over #112 . Let me know if issue cannot be resolved easy, so I will start my attempts to improve mapster.

@chaowlert
Copy link
Collaborator

Thank you for test case, now I know the problem. For performance optimization, Mapster tried to inline class mapping for example if there is only Parent and Child, class generation will be like

return new Parent {
    Child1 = new Child {
        Prop1 = Prop1,
        Prop2 = Prop2
    },
    Child2 = new Child {
        Prop1 = Prop1,
        Prop2 = Prop2
    },
}

But if class relationship is a lot, it ends up Mapster will create a very large method. And this process takes a lot of time.

I'm just have time to work on Mapster again, I just add a lot of features in https://github.com/chaowlert/Mapster (develop branch). For this issue, I think I can fix this. But if you would like to join, you can pull my repo.

Thank you,

@alexeyosipov
Copy link
Author

Thank you for explanation and fix! Hope it will appear in the nuget package soon.

For issues with easily found and fixed cause I'm interested in creating a PR with fix done by me in future.

@DmitryEvmenov
Copy link

@chaowlert Hi! Could you please tell me is there any estimate we could see the fix for this issue available in nuget?

@chaowlert
Copy link
Collaborator

There is few things I would like to add, plus some documentation. If you need the fix, I can make prerelease this weekend.

@chaowlert
Copy link
Collaborator

Hi, I just released the prerelease package (https://www.nuget.org/packages/Mapster/3.0.0-pre). Before using this package, please keep in mind that.

  1. I changed a lot (chaowlert/Mapster@2.6.1...develop), I will document what I changed later on.
  2. There should be no major breaking changes. Existing unit test works fine. But as I changed a lot, there might be corner cases where it didn't cover by unit test.

@DmitryEvmenov
Copy link

@chaowlert ,

Thanks a lot for releasing the preprelease version!
We hoped to see the fix as soon as possible, and you did it!

P.S. we can let you know if we meet some regression issue during testing the update so you're aware about some corner case that's not covered by UT :)

@chaowlert
Copy link
Collaborator

Hi, this issue should be solved in Mapster 3.0. Thx for test case, I already added in unit test. In normal cases, this problem should be fixed automatically, but if problem persists, try add AvoidInlineMapping setting (https://github.com/chaowlert/Mapster/wiki/Object-references) to tell Mapster not to use inlining.

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

3 participants