Cocos2dx&lua-ui shows how optimization resolves a large number of JSON files

Source: Internet
Author: User
Tags lua

There is a Widgetfromjsonfile method in Guireader that parses a JSON file (the Cocostudio generated UI ) and returns the parent node (Widget) of the file. It then facilitates further UI operations (such as getting the various subclasses to populate the data for display, etc.).


Then the problem comes when you need to load a large number of nodes in a page or a control (especially pages, lists, etc.), if you want to add a child node to the JSON file at about 10K or more, Then this heavy load will make the phone very painful (a few k, when the number of loading reached 50 or so, it will be stuck in 2-3 seconds).


So, it needs to be optimized here.

In fact, the idea of optimization is quite simple, first find the problem: Since the time is spent in parsing a large number of JSON files, that is, the parsed JSON here is the data you currently need to display one by one corresponding to the collection, Simply put: The reason for the card is that you have several data to parse the JSON several times (many people do this because they populate the parsed widget class directly with data). After this is optimized, you will feel that this is a very inappropriate practice.


So, it's easy to get a conclusion: to release this parsing of 1 JSON files before populating the data and adding binding operations!


Idea: Resolve only the minimum number of child nodes (or controls, especially pages) that can be displayed (this is now necessary because the same child node can have only 1 root nodes), The parsed node (widget) is then uniformly placed in a data structure (such as queue or array-on-demand customization); (Here's to explain: if a game has a 10-draw recruitment function, each recruit will display 10 cards on a single page, The display optimizer here is this: the node class that loads 10 cards on login is placed in a data structure, and after each recruitment, we need to parse the JSON of the next display interface (this is not recommended to add 10 static here, as this will make the file larger, as the previous data is bound to the UI operation). So every time the display is traversed from that data structure, fetch and populate the data into the page. After optimization, for example: here if a player points 10 even draw 10 times, I just resolved: a page of JSON * 10 + 10 card JSON, rather than (a page json+ 10 card json) *10);

later I will write some implementations to help you better understand the ideas here.



Cocos2dx&lua-ui shows how optimization resolves a large number of JSON files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.