handsomecode / InteractiveSideMenu

iOS Interactive Side Menu written in Swift.
Apache License 2.0
708 stars 164 forks source link

Performance improvement & Memory consumption #36

Open ghost opened 7 years ago

ghost commented 7 years ago

Hey guys,

Thanks for the great library. Currently contentViewControllers requires instantiated view controllers which could cause high memory usage specially with complex views. I tried to change it to array of StoryBoard identifiers and instantiate VC inside selectContentViewController() which resolves the allocation issue and I can see that previous views gets de-initialized successfully but now I am having a UI Performance issue and changing the SideMenuItemContent seems a bit slow.

Have you tried to fix the memory allocation issue in another way or do you have any suggestions that can improve the overall performance impact ?

AndreyArzhannikov commented 7 years ago

Hi, @mosn.

Thanks for this question! Actually, we didn't run into performance issue and large memory consumption. It would awesome to know details of your specific case.

So, could you describe a few things

So, it requires some investigating to suggest appropriate solution. Currently, I'd suggest trying to simplify complex layouts, investigate if it's possible to tune some views, use lazy initialization as many as possible.

ghost commented 7 years ago

Hi @AndreyArzhannikov ,

Thank you for quick response, I haven't done any profiling yet but looking at the current implementation, it seems to me that placing all instantiated view controllers inside the contentViewControllers array does not seem like best approach, Sadly use of Lazy init or tuning object will not be beneficial here since with this setup, when the object is initialize it will never de-intialize and stays in memory forever.

I think the best approach to initialize view controllers only when the sideMenu is presented and deinit when it is not activated, Which brings us to my second point of performance impact in the menus with +4 menu items. Do you know why this impact is there. I can see at various stages the subviews are removed from the view, To me it looks like that you are also trying to release the allocated memory for some of these views.

Thanks

AndreyArzhannikov commented 7 years ago

@mosn Yes, potentially we might have memory consumption issue if we have many menu items. The current implementation is not perfect in this case. A potential way to fix is to instantiate item VC by request or even caches it. Instantiating on the fly has own cost and here we need to have a lightweight view, tuning stuff and lazy initialization I mentioned before. I'm sorry for misleading you with lazy things above.

So, we added this point to our to-do list.
Thank you for addressing it and feel free to send us pull request with your solution!