DSL-based page construction method, apparatus and device, medium and program

By detecting and reusing the DSL template view tree in memory, the problem of poor performance of DSL dynamic schemes is solved, and more efficient page rendering is achieved.

CN119597277APending Publication Date: 2025-03-11BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311167431.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-11
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

The existing DSL dynamics schemes have poor performance, resulting in excessive page rendering time and resource consumption.

Method used

By detecting whether the view tree of the target DSL template exists in memory, if it does not exist, create and save, replace the page context, bind the view data to generate the rendering tree, and bind it to the current page for rendering.

Benefits of technology

This method can reuse the executable data of the loaded DSL template, reduce the time and resources required for page rendering, and improve the performance of the DSL dynamic scheme.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597277A_ABST
    Figure CN119597277A_ABST
Patent Text Reader

Abstract

Embodiments of the invention provide a DSL-based page construction method, apparatus, device, medium and program, when a target DSL template of a current page needs to be loaded, firstly detecting whether a view tree corresponding to the target DSL template exists in a memory, the memory storing executable data of the loaded DSL template, if yes, loading the target DSL template, and if not, loading the target DSL template. The executable data comprises at least one of a view tree, a node tree and a class object of the DSL template, when the view tree does not exist in the memory, creating the view tree according to the original data of the target DSL template or the executable data of the target DSL template existing in the memory, and replacing the page context of the view tree with the context of the current page, and binding the view data to obtain a rendering tree corresponding to the target view tree, and binding the rendering tree to the current page. According to the method, the executable data of the loaded DSL template can be reused to construct the current page, so that the time and resources required for rendering the current page are reduced, and the performance of a DSL dynamic scheme is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the technical field of electronic devices, and in particular, to a method, apparatus, device, medium and program for constructing a page based on DSL. Background Art

[0002] User interface (UI) is the medium for human-computer information interaction. UI is the software between the user and the hardware of the device for interaction with each other, allowing the user to effectively operate the hardware to complete the desired task.

[0003] With the abundance of applications (apps) and the diversification of application functions, the similarity between the UI components of applications has gradually increased, and the display devices of UI components have also gradually diversified. Therefore, the structured application of UI components has emerged. The structuring of UI components refers to modularizing UI components to facilitate the combination and reuse of UI components, etc., to avoid the waste of resources caused by repeated development of UI components. In the prior art, a dynamic solution based on a domain-specific language (DSL) can be used to realize the reuse of UI components. DSL uses one language to build another language, which is suitable for solving cross-domain or cross-platform problems. However, the performance of the existing DSL dynamic solution is poor. Summary of the invention

[0004] The embodiments of the present application provide a method, apparatus, device, medium and program for constructing a page based on DSL, which can reuse the executable data of a loaded DSL template to construct the current page, reduce the time and resources required for rendering the current page, and improve the performance of the DSL dynamic solution.

[0005] In a first aspect, an embodiment of the present application provides a method for constructing a page based on a DSL, the method comprising:

[0006] According to identification information of a target domain specific language DSL template associated with a current page of the application, detecting whether a view tree corresponding to the target DSL template exists in a memory, wherein executable data of the loaded DSL template is stored in the memory, wherein the executable data includes at least one of a view tree, a node tree, and a class object corresponding to the DSL template, and the DSL template is a collection of description information of a user interface UI;

[0007] When the view tree corresponding to the target DSL template does not exist in the memory, creating the view tree corresponding to the target DSL template according to the original data of the target DSL template or the executable data of the target DSL template existing in the memory and saving it in the memory;

[0008] Replacing the page context of the view tree corresponding to the target DSL template in the memory with the context of the current page to obtain the target view tree of the current page;

[0009] Obtain an expression corresponding to the target DSL template, use the expression to bind view data to the view of the target view tree, and obtain a rendering tree corresponding to the target view tree;

[0010] The rendering tree is bound to the current page, and the current page is rendered to obtain a rendering result of the current page.

[0011] In some embodiments, the class object is obtained by parsing the original data of the DSL template, the node tree is created according to the class object, and the view tree is created according to the node tree;

[0012] The node tree is used to describe the association relationship of views in the user interface UI corresponding to the DSL template through a tree structure. Each node of the node tree corresponds to a view component, and the nodes of the node tree correspond to the nodes of the view tree one by one.

[0013] The memory also stores expressions corresponding to the DSL template.

[0014] In some embodiments, the executable data of the target DSL template in the memory includes a node tree and a class object corresponding to the target DSL template, and the creating a view tree corresponding to the target DSL template according to the original data of the target DSL template or the executable data of the target DSL template in the memory and saving it to the memory includes:

[0015] Determine in sequence whether there is a node tree and a class object corresponding to the target DSL template in the memory;

[0016] When the node tree corresponding to the target DSL template exists in the memory, creating a view tree corresponding to the target DSL template according to the node tree corresponding to the target DSL template, and storing the view tree corresponding to the target DSL template in the memory;

[0017] When the class object corresponding to the target DSL template exists in the memory, a node tree and a view tree corresponding to the target DSL template are created according to the class object corresponding to the target DSL template, and expressions are extracted from the class object corresponding to the target DSL template, and the node tree, the view tree and the expressions corresponding to the target DSL template are stored in the memory;

[0018] When the class object corresponding to the target DSL template does not exist in the memory, original data of the target DSL template is obtained, a class object, a node tree, and a view tree corresponding to the target DSL template are created according to the original data of the target DSL template, expressions are extracted from the class object corresponding to the target DSL template, and the class object, the node tree, the view tree, and expressions corresponding to the target DSL template are stored in the memory.

[0019] In some embodiments, replacing the page context of the view tree corresponding to the target DSL template with the context of the current page to obtain the target view tree of the current page includes:

[0020] Determine whether the page context of the view tree corresponding to the target DSL template is the same as the context of the current page;

[0021] If the page context of the view tree corresponding to the target DSL template is the same as the context of the current page, determining that the view tree corresponding to the target DSL template is the target view tree;

[0022] If the page context of the view tree corresponding to the target DSL template is different from the context of the current page, the page context of the view tree corresponding to the target DSL template is replaced with the context of the current page to obtain the target view tree.

[0023] In some embodiments, the view tree corresponding to the target DSL template includes a proxy context, and the proxy context references the page context by means of a weak reference or a soft reference;

[0024] The replacing the page context of the view tree corresponding to the target DSL template with the context of the current page includes:

[0025] The page context referenced by the proxy context of the view tree corresponding to the target DSL template through weak reference or soft reference is replaced with the context of the current page.

[0026] In some embodiments, the loaded DSL template includes a preloaded DSL template and / or a real loaded DSL template, and before detecting whether a view tree corresponding to the target DSL template exists in the memory, the method further includes:

[0027] When a preset first condition is met, predicting a DSL template used by the application in the future, using the DSL template used in the future as a preloaded DSL template, creating executable data of the preloaded DSL template in an asynchronous manner, and storing the executable data in the memory;

[0028] And / or, when constructing other pages for the application, creating executable data of the DSL template associated with the other pages and storing it in the memory, wherein the DSL template associated with the other pages is the actually loaded DSL template.

[0029] In some embodiments, the creating the executable data of the preloaded DSL template and storing it in the memory includes:

[0030] Obtaining original data of the preloaded DSL template;

[0031] Parsing the original data of the preloaded DSL template to obtain a class object corresponding to the preloaded DSL template, and storing the class object corresponding to the preloaded DSL template in the memory;

[0032] Creating a node tree corresponding to the preloaded DSL template according to the class object corresponding to the preloaded DSL template, and storing the node tree corresponding to the preloaded DSL template in the memory;

[0033] Creating a view tree corresponding to the preloaded DSL template according to the node tree corresponding to the preloaded DSL template, and storing the view tree corresponding to the preloaded DSL template in the memory;

[0034] Expressions are extracted from the class objects corresponding to the preloaded DSL template, and information of the extracted expressions is stored in the memory.

[0035] In some embodiments, the first condition includes one or more of the following conditions: detecting that the number of view trees stored in the memory is less than a first preset number, detecting that the application has idle threads, detecting that a preconfigured period has arrived, and detecting that the application is started.

[0036] In some embodiments, the view tree corresponding to the target DSL template is created in the following manner:

[0037] Traversing the nodes of the node tree corresponding to the target DSL template, searching for a corresponding view from the view cache pool in the memory according to the view type of the node in the node tree corresponding to the target DSL template, wherein the view cache pool stores a plurality of pre-created views;

[0038] When the view corresponding to the current node is found from the view cache pool, the found view is added to the current node;

[0039] When the view corresponding to the current node is not found in the view cache pool, a view is created for the current node according to the view type of the current node.

[0040] In some embodiments, the method further comprises:

[0041] When a preset second condition is met, a new view is created and stored in the view cache pool;

[0042] The second condition includes one or more of the following conditions: detecting that a preset page is started, detecting that an application thread is idle, detecting that an application is started, or detecting that the number of views in the view cache pool is less than a second preset number.

[0043] In some embodiments, the obtaining the original data of the target DSL template includes:

[0044] Reading the original data of the DSL template from an internal folder of the application stored locally according to the identification information of the target DSL template;

[0045] When the original data of the target DSL template is not stored in the internal folder of the application, requesting the original data of the target DSL template from the server according to the template name or storage address of the target DSL template;

[0046] receiving information of the target DSL template returned by the server, where the information of the target DSL template includes original data, a version number, and an information digest value of the target DSL template;

[0047] The original data of the target DSL template and the identification information of the target DSL template are stored in an internal folder of the application, where the identification information of the target DSL template includes the name, version number and information summary value of the target DSL template.

[0048] In some embodiments, obtaining the expression corresponding to the target DSL template includes:

[0049] Acquire an expression corresponding to the target DSL template from the memory, where the expression corresponding to the target DSL template is generated in a process of creating executable data of the target DSL template;

[0050] When the expression corresponding to the target DSL template cannot be obtained from the memory, a class object corresponding to the target DSL template is obtained from the memory, and an expression is extracted from the class object corresponding to the target DSL template to obtain the expression corresponding to the target DSL template, and the expression is stored in the expression corresponding to the target DSL template.

[0051] In some embodiments, the rendering tree is bound to the current page through a main thread of the application, and the rendering tree is obtained through an auxiliary thread of the application.

[0052] In some embodiments, the target DSL template includes three types of description information, wherein the first type of description information is used to describe the association relationship of views in the UI, the second type of description information is used to describe the style and layout of the views in the UI, and the third type of description information is used to describe the data binding logic of the views.

[0053] In a second aspect, an embodiment of the present application provides a device for constructing a page based on DSL, the device comprising:

[0054] a detection module, configured to detect whether a view tree corresponding to a target domain specific language DSL template exists in a memory according to identification information of the target domain specific language DSL template associated with a current page of the application, wherein executable data of the loaded DSL template is stored in the memory, wherein the executable data includes at least one of a view tree, a node tree, and a class object corresponding to the DSL template, and the DSL template is a collection of description information of a user interface UI;

[0055] a creating module, configured to create a view tree corresponding to the target DSL template according to original data of the target DSL template or executable data of the target DSL template existing in the memory and save the view tree to the memory when the view tree corresponding to the target DSL template does not exist in the memory;

[0056] A replacement module, used to replace the page context of the view tree corresponding to the target DSL template existing in the memory with the context of the current page, to obtain the target view tree of the current page;

[0057] A data binding module, used to obtain an expression corresponding to the target DSL template, and use the expression to bind view data to the view of the target view tree to obtain a rendering tree corresponding to the target view tree;

[0058] The rendering module is used to bind the rendering tree to the current page, render the current page, and obtain a rendering result of the current page.

[0059] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory, the memory being used to store a computer program, the processor being used to call and run the computer program stored in the memory to execute a method as described in any one of the above-mentioned first aspects.

[0060] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program enables a computer to execute the method as described in any one of the first aspects above.

[0061] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the method described in any one of the first aspects above.

[0062] The method, apparatus, device, medium and program for building a page based on DSL provided by the embodiment of the present application, when the target DSL template of the current page needs to be loaded, first detect whether there is a view tree corresponding to the target DSL template in the memory, the memory stores the executable data of the loaded DSL template, the executable data includes at least one of the view tree, node tree and class object of the DSL template, when the view tree does not exist in the memory, create the view tree according to the original data of the target DSL template or the executable data of the target DSL template in the memory, replace the page context of the view tree with the context of the current page, obtain the target view tree of the current page, bind the view data to the view of the target view tree, obtain the rendering tree corresponding to the target view tree, and bind the rendering tree to the current page. The method can reuse the executable data of the loaded DSL template to build the current page, reduce the time and resources required for rendering the current page, and improve the performance of the DSL dynamic solution. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0064] Figure 1 A flowchart of a method for constructing a page based on DSL provided in Embodiment 1 of the present application;

[0065] Figure 2 A flowchart of the preloading process of the DSL template provided in the second embodiment of the present application;

[0066] Figure 3 This is a schematic diagram of the principle of the DSL template preloading process;

[0067] Figure 4 A schematic diagram of the node tree and view tree of the DSL template;

[0068] Figure 5 A flowchart of a method for constructing a page based on DSL provided in Embodiment 3 of the present application;

[0069] Figure 6 A schematic diagram of the structure of a device for constructing a page based on DSL provided in Embodiment 4 of the present application;

[0070] Figure 7A schematic diagram of the structure of an electronic device provided in Example 5 of the present application. DETAILED DESCRIPTION

[0071] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0072] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.

[0073] The embodiment of the present application provides a method for constructing a page based on DSL, which can be applied in an application (application, APP) of an Android system to construct a page of an app of the Android system.

[0074] The following describes some concepts involved in the embodiments of the present application.

[0075] A DSL template is a collection of UI description information and is a custom DSL file. The DSL template includes three types of description information. The first type of description information is used to describe the association relationship between views in the UI. The second type of description information is used to describe the style and layout of the View in the UI. The third type of description information is used to describe the data binding logic of the View.

[0076] Exemplarily, the DSL template includes three sub-DSL files, namely: index.json file, index.css file and index.databining file, wherein the index.json file is used to store the first type of description information, the index.css file is used to store the second type of description information, and the index.databining file is used to store the third type of description information.

[0077] The index.json file uses the Json format. The information in the file describes the association relationship between the views in the UI corresponding to the DSL template, including but not limited to: the hierarchical relationship, parallel relationship, and nested relationship of the views. The index.css file uses the Cascading Style Sheets (Css) format. The information in the file describes the layout information and style information of each view in the UI.

[0078] The index.databining file uses the Json format and describes the data binding logic of each view in the UI. The data binding logic can be implemented through custom expressions. The expressions support value operations, function calculations, comparisons, conditions, and other calculations.

[0079] The APP uses DSL dynamic architecture to build UI. DSL dynamicity is mainly reflected in the following two aspects:

[0080] Dynamic templates: DSL templates can be stored in the server, and can be sent and updated through the network. DSL templates can be dynamically sent to the APP of the terminal device. When the content or style of the UI needs to be adjusted, the DSL template stored in the server is modified. The modified DSL template has a new version number. The server sends the latest DSL template to the APP, completing the dynamic update of the DSL template.

[0081] The logic dynamics of the template. The index.databining of the DSL template provides expressions. In the DSL dynamic framework, the main function of the expression is to obtain or operate on data (or view data) and bind it to the view. It is the basis of logic dynamics. By dynamically assigning different view data to the expression, the UI corresponding to the DSL template can be changed, including but not limited to changing the content and style of the UI, such as changing the color, size and font size of the text in the UI.

[0082] The DSL dynamic architecture allows UI components to be reused, used across platforms, adapted to different screen sizes, adapted to different types of devices, etc. It is easy to modify and has low development and maintenance costs.

[0083] It should be noted that the format of the original data of the DSL template is not limited to the Json format, and other formats may be used. Accordingly, the format of the sub-files included in the DSL template will also change, wherein the original data of the DSL template refers to the string code of the DSL template stored on the server side.

[0084] After receiving the DSL template from the server, the terminal device's APP cannot directly use the DSL template. It needs to parse and process the original data of the DSL template to obtain the executable data of the DSL template, where the executable data of the DSL template refers to data that can be recognized or directly called by the native components of the terminal device. The terminal device can parse and process the content of the original data of the DSL template through the Software Development Kit (SDK).

[0085] The executable data of the DSL template includes the class object, node tree and view tree corresponding to the DSL template. The class object parses the original data of the DSL template to obtain the class structure that the APP can recognize, and stores the parsed class object in the memory.

[0086] After parsing the class object, a node tree is created based on the class object. The node tree is used to describe the association relationship of the views in the UI corresponding to the DSL template through a tree structure. Each node in the node tree corresponds to a view component. The information of each node includes: node ID, view type (also called node type), parent node of the node, child node of the node, view style, view layout and other information. View types include but are not limited to: image view, text view, view, etc.

[0087] After creating the node tree, create a view tree based on the node tree. The nodes of the node tree correspond to the nodes of the view tree one by one. Create a view for each node based on the information of each node to form a view tree. That is, the tree structure of the node tree is the same as the tree structure of the view tree. The view tree forms a rendering tree after binding with the view data. The view in the rendering tree is a native view, which can be directly rendered by the native components of the APP to obtain a visual view.

[0088] The terminal device in this embodiment may be a mobile phone, a tablet computer, a laptop computer, a personal digital assistant, or other intelligent terminals.

[0089] In the prior art, when a page needs to be rendered, the APP obtains the original data of the DSL template associated with the page, parses and processes the original data of the DSL template to obtain the view tree of the DSL template, binds the DSL template tree to obtain a rendering tree, binds the rendering tree to the page, and renders the page. In this method, it takes a long time to create a view tree for the DSL template associated with the page in real time, which leads to a long rendering time of the page, and the view tree created for a certain page cannot be reused by other pages, resulting in a waste of resources.

[0090] In order to solve the problems of the prior art, an embodiment of the present application provides a method for building a page using DSL, which can reuse the view tree created for other pages or the pre-created view tree, thereby reducing the time and resources required for page rendering and improving the performance of the DSL dynamic solution.

[0091] Figure 1 This is a flowchart of a method for constructing a page based on DSL provided in Embodiment 1 of the present application. The method of this embodiment can be executed by a terminal device, such as Figure 1 As shown, the method provided in this embodiment includes the following steps:

[0092] S101. According to identification information of a target DSL template associated with a current page of an application, it is detected whether a view tree corresponding to the target DSL template exists in a memory.

[0093] After the user starts the APP on the terminal device, the APP needs to render the page during operation. The terminal device displays different pages according to the user's operation. When the APP page changes, the page needs to be rendered.

[0094] When the current page of the APP needs to be rendered, the identification information of the DSL template associated with the current page is obtained. The DSL template is a collection of UI description information. The current page may be associated with one or more DSL templates. For example, the DSL template associated with the page is defined when the page is created. The identification information of the DSL template is used to uniquely identify a DSL template. The identification information of the DSL template may include the name of the DSL template. In order to facilitate the distinction between DSL templates, the DSL template associated with the current page is called the target DSL template.

[0095] If multiple version numbers are set for the same DSL template, and different version numbers correspond to different original data of the DSL template, the identification information of the DSL template also includes the version number. A DSL template can be uniquely identified according to the name and version number of the DSL template.

[0096] Optionally, the identification information of the DSL template also includes an information digest value of the DSL template. The information digest value of the DSL template is a value calculated by using an information digest algorithm for original data of the DSL template. When the original data of the DSL template is different, the corresponding information digest value is also different. Information digest algorithms include but are not limited to MD5, MD4, MD3, MD2, etc., among which MD5 is a currently commonly used information digest algorithm, and MD5 is improved from MD4, MD3, and MD2.

[0097] When the APP wants to call the target DSL template associated with the current page, it needs to load the target DSL template into the memory first. Loading the DSL template means generating or creating the executable data of the DSL template in the memory, storing the generated or created executable data in the memory, and the APP calls the executable data of the target DSL template from the memory.

[0098] In this embodiment, the terminal device does not directly create the executable data of the target DSL template according to the identification information of the target DSL template associated with the current page, but first detects whether there is a view tree corresponding to the target DSL template in the memory according to the identification information of the target DSL template associated with the current page. If the view tree corresponding to the target DSL template exists in the memory, step S103 is executed. If the view tree corresponding to the target DSL template does not exist in the memory, step S102 is not executed to create the view tree corresponding to the DSL template.

[0099] In this embodiment, the memory stores executable data of one or more loaded DSL templates, and the executable data includes at least one of a view tree, a node tree, and a class object corresponding to the DSL template.

[0100] A loaded DSL refers to a DSL whose executable data has been generated or created in the memory before the current page is triggered to render. The number of loaded DSL templates stored in the memory may be 0, 1, or more. For example, when the app is just started, no DSL template of the app has been loaded in the memory. At this time, the number of loaded templates in the memory is 0.

[0101] In this embodiment, the loaded DSL template includes a preloaded DSL template and / or a real loaded DSL template. Preloading means that when a preset first condition is met, executable data is pre-created for a DSL template that may be used in the future in an asynchronous manner. The preloaded DSL template is a DSL template that may be used in the future. By preloading, the executable data of the DSL template that may be used in the future can be loaded into the memory in advance. When the page of the application is subsequently rendered, the executable data of the preloaded DSL template can be directly read from the memory without the need to load the DSL template in real time, thereby saving the time required to load the DSL template.

[0102] The real loaded DSL template refers to the DSL template associated with other pages that have been built. It is the DSL template loaded in real time for the other page when the other page is built for the application. When the terminal device builds other pages for the application, it creates the executable data of the DSL template associated with the other page and stores it in the memory. The DSL template associated with the other page can be reused by other pages later, avoiding the waste of resources caused by repeated loading of DSL templates.

[0103] Optionally, the first condition includes one or more of the following conditions: detecting that the number of view trees stored in the memory is less than a first preset number, detecting that the application has an idle thread, detecting that a preconfigured period has arrived, and detecting that the application is started. When the terminal device detects that the first condition is met, it predicts a DSL template used by the application in the future, and preloads the DSL template used in the future into the memory.

[0104] In this embodiment, the executable data of the loaded DSL template stored in the memory can be reused by the same page or by multiple different pages, that is, reused across pages, thereby avoiding the waste of computing resources and storage resources caused by repeated loading of the DSL template. In addition, loading the DSL template requires a certain amount of time. The current page directly uses the executable data of the loaded DSL template from the memory, saving the time for real-time loading of the DSL template and shortening the rendering cycle of the current page.

[0105] In one implementation, the class objects, node trees and view trees of the loaded DSL templates are stored in a cache pool in the memory, and the data of different DSL templates in the cache pool are distinguished by identification information of the DSL templates.

[0106] In another implementation, the class objects, node trees, and view trees of the loaded DSL templates are stored in different cache pools in the memory, for example, three cache pools are set in the memory: a class object cache pool, a node tree cache pool, and a view tree cache pool, wherein the class object cache pool is used to store the class objects of the loaded DSL templates, the node tree cache pool is used to store the node trees of the loaded DSL templates, and the view tree cache pool is used to store the view trees of the loaded DSL templates. The data of different DSL templates in each cache pool are distinguished by the identification information of the DSL templates.

[0107] S102: Create a view tree corresponding to the target DSL template according to the original data of the target DSL template or the executable data of the target DSL template in the memory and save it in the memory.

[0108] When the view tree corresponding to the target DSL template does not exist in the memory, it is necessary to create the view tree corresponding to the target DSL template. For example, the view tree corresponding to the target DSL template may not exist in the memory in the following scenarios:

[0109] Scenario 1: The loaded DSL templates do not include the target DSL template. In this case, the class object, node tree, and view tree corresponding to the target DSL template are not stored in the memory.

[0110] Scenario 2: The loaded DSL templates include the target DSL template, but the view tree corresponding to the target DSL template is used by a UI component of the current page or a UI component of another page. In this scenario, although the view tree corresponding to the target DSL template is not stored in the memory, the class object and / or node tree corresponding to the target DSL template is stored in the memory.

[0111] In scenario 2, a view tree can only be used by one UI component in the page. In actual scenarios, multiple UI components in the current page may need to use the same view tree. For example, the first UI component and the second UI component in the current page both need to use the same view tree. After the first UI component uses the view tree, the view tree does not exist in the memory. At this time, if the second UI component needs to use the view tree, it needs to recreate the view tree. Alternatively, if the view tree has been used by the previous page, the view tree does not exist in the memory. If the current page wants to use the view tree, it needs to recreate the view tree. It should be noted that in scenario 2, there may be other situations that cause the class object or node tree corresponding to the target DSL template to be stored in the memory, but the view tree corresponding to the target DSL template is not stored.

[0112] For scenario 1, the terminal device can only obtain the original data of the target DSL template, and create a view tree corresponding to the target DSL template according to the original data of the target DSL template.

[0113] For scenario 2, the terminal device can create a view tree in the following two ways:

[0114] Method 1: obtain the original data of the target DSL template, and create a view tree corresponding to the target DSL template according to the original data of the target DSL template.

[0115] The complete process of creating a view tree corresponding to a target DSL template includes: obtaining the original data of the DSL template, parsing the original data of the target DSL template to obtain a class object, creating a node tree based on the class object, and creating a view tree based on the node tree. Therefore, the time and resources required to create a view tree corresponding to a DSL template vary depending on different data.

[0116] In this method, no matter whether the executable data of the target DSL template exists in the memory, the original data of the DSL template is used to create the view tree corresponding to the target DSL template.

[0117] Method 2: Create a view tree corresponding to the DSL template in a hierarchical manner. Creating a view tree corresponding to the DSL template is also called loading the DSL template in a hierarchical manner.

[0118] Hierarchical creation means creating a view tree corresponding to a DSL template based on data of different levels. The time and computing resources required to create a view tree using data of different levels are different. Hierarchical creation data includes three levels: the first level data refers to the node tree corresponding to the DSL template, the second level data refers to the class object corresponding to the DSL template, and the third level data refers to the original data of the DSL template. The first level is higher than the second level, and the second level is higher than the third level. When creating hierarchically, create from high to low levels in sequence. If there is high-level data, use the high-level data to create the view tree. If there is no high-level data, use the lower-level data to create the view tree.

[0119] Exemplarily, the hierarchical creation process includes: determining in sequence whether there are node trees and class objects corresponding to the target DSL template in the memory; when there is a node tree corresponding to the target DSL template in the memory, creating a view tree corresponding to the target DSL template according to the node tree corresponding to the target DSL template, and storing the view tree corresponding to the target DSL template in the memory. When there is a class object corresponding to the target DSL template in the memory, creating a node tree and a view tree corresponding to the target DSL template according to the class object corresponding to the target DSL template, performing expression extraction on the class object corresponding to the target DSL template, and storing the node tree, view tree and expression corresponding to the target DSL template in the memory.

[0120] When the class object corresponding to the target DSL template does not exist in the memory, the original data of the target DSL template is obtained, the class object, node tree and view tree corresponding to the target DSL template are created according to the original data of the target DSL template, and the expression of the class object corresponding to the target DSL template is extracted, and the class object, node tree, view tree and expression corresponding to the target DSL template are stored in the memory.

[0121] The most time-consuming process of creating executable data for a DSL template is the data parsing process (i.e., the process of parsing class objects) and the process of creating a node tree. Therefore, when the view tree corresponding to the target DSL template does not exist in the memory, hierarchically creating the view tree corresponding to the target DSL template can also save the time and resources required to load the DSL template, compared to creating the view tree according to the original data corresponding to the DSL template.

[0122] S103: Replace the page context of the view tree corresponding to the target DSL template in the memory with the context of the current page to obtain the target view tree of the current page.

[0123] The view tree corresponding to the target DSL template used in this step can be a view tree pre-loaded from memory or a view tree created in real time. The view tree includes one or more views, and the views in the view tree are also called subviews of the view tree.

[0124] The page context of the view tree refers to the page context of the view in the view tree. Each view in the view tree has a page context, and the page context of each view in the view tree is the same. The page context can be understood as an instance of a page. The page contexts of different pages are different. For example, after the user opens the APP, the login page is displayed first, and then the main page is entered. The page contexts of the login page and the main page are different. After entering the main page, you can jump to a sub-page based on the user's operation. The page context of the sub-page is different from the page context of the main page.

[0125] The page context of the view tree corresponding to the target DSL template is the context of the page where the view tree is created. Therefore, the page context of the view tree corresponding to the target DSL template may be the context of the current page, or it may not be the context of the current page. For example, if the target DSL template is a preloaded DSL template, and the page where the terminal device preloads the target DSL template is the first page, then the page context of the view tree corresponding to the target DSL template is the context of the first page, which is different from the current page.

[0126] In one implementation, after obtaining the view tree corresponding to the target DSL template, regardless of whether the page context of the view tree is the context of the current page, a page context replacement operation is performed to replace the page context of the view tree with the context of the current page.

[0127] In another implementation, after obtaining the view tree corresponding to the target DSL template, it is determined whether the page context of the view tree corresponding to the target DSL template is the same as the context of the current page. If the page context of the view tree corresponding to the target DSL template is the same as the context of the current page, the view tree corresponding to the target DSL template is determined to be the target view tree, that is, the page context replacement operation is not performed. If the page context of the view tree corresponding to the target DSL template is not the same as the context of the current page, the page context of the view tree corresponding to the target DSL template is replaced with the context of the current page to obtain the target view tree.

[0128] In this embodiment, the cross-page reuse of the view tree is achieved by replacing the page context of the view tree. The cross-page reuse of the view tree shortens the page rendering time and improves the page rendering efficiency. However, in the prior art, after a view tree is created, the upper and lower pages of the view tree cannot be replaced, and the view tree cannot be reused by other pages.

[0129] Exemplarily, in this embodiment, a proxy context is used to implement page context replacement. The view tree corresponding to the target DSL template includes a proxy context, and the proxy context references the page context through a weak reference or a soft reference. When replacing, the page context referenced by the proxy context of the view tree corresponding to the target DSL template through a weak reference or a soft reference is replaced with the context of the current page.

[0130] In the prior art, when creating a view tree, the context of the current page is directly used as a parameter for creation. Therefore, the page context of the created view tree is the context of the current page, and the page context of the view tree created in this way cannot be modified. However, the method of this embodiment creates a proxy context before creating the view tree, creates the proxy context as a parameter, and saves the page context to the proxy context through a weak reference or a soft reference. The object referenced by the proxy context (i.e., the page context) can be replaced.

[0131] S104. Obtain an expression corresponding to the target DSL template, use the expression to bind view data to the view of the target view tree, and obtain a rendering tree corresponding to the target view tree.

[0132] All or part of the views in the target view tree obtained above lack view data, and / or the data of some views need to be modified. For example, some views in the target view tree use some default data when they are created, and the default data needs to be modified. Therefore, the view data needs to be bound to the corresponding view tree through data binding.

[0133] Data binding is a major way to implement DSL dynamics. Data binding is implemented through the expression corresponding to the DSL template. The view data is assigned to the expression, and the view data of the view is calculated through the expression to obtain the final data of the view.

[0134] If the expression corresponding to the target DSL template exists in the memory, the expression is read from the memory. The expression in the memory is extracted from the class object of the target DSL template during the loading process of the target DSL template. If the expression corresponding to the target DSL template does not exist in the memory, the class object corresponding to the DSL template is obtained from the memory, and the expression is extracted from the class object corresponding to the target DSL template. The extracted expression can be stored in the memory and reused by other pages.

[0135] The view data may be sent by the server to the terminal device, or the view data may be stored locally. For example, when the server sends the original data of the target DSL template to the terminal device, the server also sends the view data of the target DSL template to the terminal device. The terminal device stores the original data of the target DSL template and the view data together in an internal file of the APP. The view data may also be obtained in other ways, which is not limited in this embodiment.

[0136] Exemplarily, the view data includes text content, size, color, style, etc., or includes the address and size of a picture, etc. By binding the view data to the target view tree, the content and style of the view can be modified dynamically.

[0137] S105: Bind the rendering tree to the current page, render the current page, and obtain a rendering result of the current page.

[0138] The rendering tree can be directly rendered by the APP. After the rendering tree is bound to the current page, the terminal device can use the native rendering component to render the current page, obtain the rendering result of the current page, and display the rendering result on the screen.

[0139] The APP includes a main thread and multiple auxiliary threads. The rendering tree is bound to the current page through the main thread of the APP, and the rendering operation of the current page is performed by the main thread.

[0140] Optionally, the rendering tree may be obtained through a main thread, or through an auxiliary thread of the APP, where obtaining the rendering tree includes steps S101 to S104.

[0141] The method of executing steps S101-S104 through the auxiliary thread of the APP and executing step S105 through the main thread of the APP is called asynchronous rendering. In the asynchronous rendering method, after step S104, it is necessary to switch from the auxiliary thread to the main thread. It can be understood that during the process of the auxiliary thread executing steps S101-S104, the main thread can execute other operations in parallel, thereby reducing the load of the main thread, shortening the rendering time, and improving rendering efficiency.

[0142] In this embodiment, when the target DSL template of the current page needs to be loaded, firstly detect whether there is a view tree corresponding to the target DSL template in the memory, the memory stores the executable data of the loaded DSL template, and the executable data includes at least one of the view tree, node tree and class object of the DSL template. When the view tree does not exist in the memory, the view tree is created according to the original data of the target DSL template or the executable data of the target DSL template in the memory, the page context of the view tree is replaced with the context of the current page, the target view tree of the current page is obtained, the view data is bound to the view of the target view tree, the rendering tree corresponding to the target view tree is obtained, and the rendering tree is bound to the current page. This method can reuse the executable data of the loaded DSL template to construct the current page, reducing the time and resources required for rendering the current page.

[0143] Based on the first embodiment, the second embodiment of the present application provides a DSL template preloading method, which is used to preload the DSL template, that is, to create executable data of the preloaded DSL template. Figure 2 This is a flowchart of the preloading process of the DSL template provided in the second embodiment of the present application. Figure 3 This is a schematic diagram of the DSL template preloading process. Figure 2 and Figure 3 , the method provided in this embodiment includes the following steps.

[0144] S201: Obtain original data of a DSL template.

[0145] In the first implementation method, the DSL templates of the APP are stored in the internal files of the APP. The internal files are usually stored in the local hard disk or disk of the terminal device. The DSL templates are stored locally with the installation files during the APP installation process. When the DSL template needs to be loaded, the original data of the DSL template is read from the local internal files according to the identification information of the DSL template.

[0146] In the second implementation manner, the terminal device requests the original data of the DSL template from the server according to the template name or storage address of the DSL template.

[0147] The terminal device may actively request the original data of the DSL template from the server when the APP is started; or, after the APP is started, the terminal device periodically requests the original data of the DSL template from the server.

[0148] The DSL template on the server is updated dynamically. By actively requesting the original data of the DSL template from the server, the APP can ensure that the latest DSL template can be used when the APP is running.

[0149] In the third implementation, when a DSL template needs to be loaded, the original data of the DSL template is first read from the internal folder of the locally stored application according to the identification information of the target DSL template. If the original data of the target DSL template is not stored in the internal folder of the application, the original data of the target DSL template is requested from the server according to the template name or storage address of the target DSL template.

[0150] In a fourth implementation manner, the information of the DSL template sent by the server is received, where the information of the DSL template includes original data, a version number, and an information digest value of the DSL template.

[0151] In this implementation, the server can actively send DSL template information to the terminal device. When the DSL template stored in the server is updated, the server actively sends the updated DSL template information to the terminal device; or, the server periodically sends the updated DSL template information to the terminal device; so that the terminal device can obtain the latest DSL template.

[0152] When the server sends the information of the DSL template to the terminal device, it may only send the updated DSL templates, and not send the DSL templates that are not updated, thereby saving the transmission resources between the server and the terminal device.

[0153] The storage address of the target DSL template may be a network address. The terminal device sends the network address to the server, and the server returns the original data of the target DSL template according to the network address.

[0154] The DSL template information sent by the server to the terminal device includes the original data, version number and information digest value of the DSL template. The terminal device determines whether the version number and information digest value of the DSL template sent by the server are the same as the version number and information digest value of the DSL template stored locally. If they are the same, it is determined that the DLS template has not been updated and there is no need to re-store the DLS template. If not, it is determined that the DSL template has been updated, and the original data of the DSL template and the identification information of the DSL template are stored in the internal folder of the application. The identification information of the DSL template includes the name, version number and information digest value of the DSL template.

[0155] Reference Figure 3 As shown, the original data of the DSL template is stored in the original data pool, which is used to store the original data of the DSL template. The original data pool is located in the internal file of the APP, and the internal file is stored in the hard disk or disk of the terminal device. By storing the original data of the DSL template in the internal file of the APP, the original data of the DSL template can still be obtained locally when the APP is cold started next time.

[0156] S202: parse the original data of the DSL template to obtain a class object corresponding to the DSL template, and store the class object corresponding to the DSL template in a memory.

[0157] The original data of the DSL template can be parsed through the template parsing module. The template parsing module is used to parse the original string of the template into a template entity class. The template parsing module adopts different data parsing methods according to the different data formats used by the original data of the DSL template, and parses the original data into a specified class structure. The class structure more specifically represents the data format to be used by the DSL dynamic framework.

[0158] Taking the original data of the DSL template in JSON format as an example, the original data of the DSL template includes index.json file, index.css file and index.databining file. The index.json file is used to store the association relationship of the views in the UI, the index.css file is used to store the style and layout of the views in the UI, and the index.databining file is used to store the data binding logic of the views in the UI.

[0159] The template parsing module parses the index.json file, index.css file and index.databining file into a key-value pair (i.e. key-value) structure through JSON parsing and stores it in memory for subsequent indexing.

[0160] Reference Figure 3 As shown, the class object obtained by JSON parsing is stored in the object cache pool in the memory, which is used to store the data parsing results of the DSL template that has been loaded or is being loaded in the APP. The key of the class object stored in the object cache pool is the identification information of the DSL template, which can be the name, version number and md5 value of the DSL template.

[0161] S203: Create a node tree corresponding to the DSL template according to the class object corresponding to the DSL template, and store the node tree corresponding to the DSL template in the memory.

[0162] The class object corresponding to the DSL template cannot be directly used for rendering native components of the Android system. The class object needs to be converted into a node tree. The node tree creation process is used to convert the class object into a tree structure. Each node of the node tree corresponds to a view component. The information of each node includes: node ID, view type, parent node of the node, child node of the node, view style, view layout and other information.

[0163] After creating the node tree, store the node tree in memory, such as Figure 3As shown, the node tree is stored in the node tree cache pool, which is used to store the node tree corresponding to the DSL template that has been loaded or is being loaded in the APP. The node tree is stored in the node tree cache pool, and specifically, the root node of the node tree is stored in the node tree cache pool, so the node tree cache pool is also called the node tree root node cache pool, and the key of the root node of the node tree is the identification information of the DSL template, and the identification information can be the name, version number and md5 value of the DSL template.

[0164] S204. Create a view tree corresponding to the DSL template according to the node tree corresponding to the DSL template, and store the view tree in memory.

[0165] In an exemplary manner, a view tree is created in the following manner: traverse the nodes of the node tree corresponding to the DSL template, and search for the corresponding view from the view cache pool in the memory according to the view type of the node in the node tree corresponding to the DSL template, wherein the view cache pool stores multiple pre-created views. When the view corresponding to the current node is found in the view cache pool, the found view is added to the current node; when the view corresponding to the current node is not found in the view cache pool, a view is created for the current node according to the view type of the current node.

[0166] In this method, a view cache pool is set in the memory to store pre-created views. By pre-creating views, views that may be used by the APP are created and stored in the view cache pool in advance. When creating the view tree, the required views can be read directly from the view cache pool without real-time creation, thereby shortening the time to create the view tree.

[0167] When creating a view tree, the terminal device starts accessing nodes from the root node of the node tree, traversing the nodes of the node tree layer by layer. When accessing the current node, first determine whether the view corresponding to the view type of the current node is stored in the view cache pool. If the view corresponding to the current node is stored in the view cache pool, there is no need to create a view corresponding to the current node. The view corresponding to the current node is directly read from the view cache pool and added to the current node. If the view corresponding to the current node is not stored in the view cache pool, a view is created for the current node according to the view type of the current node. And so on, until all nodes of the node tree are visited, the view tree is also successfully created.

[0168] Optionally, when a preset second condition is met, the terminal device creates a new view and stores it in the view cache pool.

[0169] Exemplarily, the second condition includes one or more of the following conditions: detecting that a preset page is started, detecting that an application thread is idle, detecting that an application is started, or detecting that the number of views in the view cache pool is less than a second preset number.

[0170] There are many pages in the APP. You can configure to pre-create views when a special page is started, or you can choose to pre-create views when the APP thread is idle. By pre-creating views when the APP thread is idle, you can provide load balancing for the APP process. The views in the view cache pool cannot be reused, so the views in the view cache pool are constantly consumed. When the number of views in the view cache pool is less than the second preset number, you need to replenish the views immediately.

[0171] In another exemplary embodiment, no view cache pool is set in the memory, and the terminal device creates a view for the current node in real time according to the view type of the node in the node tree.

[0172] Reference Figure 3 As shown, the view tree can be stored in the view tree cache pool of the memory, and the view tree cache pool is used to store the view tree corresponding to the DSL template that has been loaded or is being loaded in the APP. The view tree is stored in the view tree cache pool, and specifically, the root node of the view tree is stored in the view tree cache pool, so the view tree cache pool is also called the view tree root node cache pool, and the key of the root node of the node tree is the identification information of the DSL template, and the identification information can be the name, version number and md5 value of the DSL template.

[0173] Figure 4 A schematic diagram of the node tree and view tree of the DSL template, such as Figure 4 As shown, the node tree and view tree of the DSL template have the same tree structure, but the content of each node in the node tree and the view tree is different. Each node in the view tree is a view, and each node in the node tree is a logical node. The node information refers to the above description.

[0174] S205: Extract expressions from the class object corresponding to the DSL template, and store information of the extracted expressions in the memory.

[0175] In the DSL dynamic framework, the main function of the expression is to obtain or operate on the data and bind it to the view of the view tree. The expression extraction process can also be called the expression parsing process or compilation process. In this embodiment, the class object includes expression strings, which cannot be recognized by the rendering engine or APP of the Android system, so it is necessary to convert the expression strings into expressions that can be recognized by the rendering engine or APP through the extraction process.

[0176] Exemplarily, the process of extracting an expression includes lexical analysis, grammatical analysis, and semantic analysis. Lexical analysis is used to divide and classify words in an expression string to obtain a meaningful morpheme sequence. Syntactic analysis is based on lexical analysis, which combines morpheme sequences into phrases and determines the correctness of the expression structure, ultimately forming a syntax tree that conforms to grammatical rules. Semantic analysis is to analyze the semantics of an expression based on a syntax tree to determine whether the semantics conform to the rules.

[0177] The information of the expression is stored in the expression cache pool, which is located in the memory. The information of the expression stored in the memory can use the hash code of the expression string as the key. In Java, each object has a hash code, which uniquely identifies an object.

[0178] Optionally, the information of the extracted expression can be stored in a least recently used (Least Recently Used, referred to as LRU) memory list. The LRU algorithm is a commonly used aging algorithm. When the storage space is limited, it can use the simplest method to clean up unused resources to free up space for other recently used data to store, thereby avoiding excessive memory overhead. It can be understood that other memory management algorithms can also be used to manage the expressions of the DSL template, and the embodiments of the present application are not limited to this.

[0179] It should be noted that step S203 and step S205 are not executed in any order and can be executed simultaneously. In addition, step S205 is an optional step, and the expression may not be extracted during the DSL template loading process, but the expression may be extracted according to the class object when the view data is bound to the view tree.

[0180] The method of this embodiment can be used to preload a DSL template. By preloading the DSL template, when the DSL template needs to be used, the executable data of the preloaded DSL template is directly read from the memory, and there is no need to create the executable data of the DSL template in the memory in real time, thereby saving the rendering time of the page.

[0181] Based on the first and second embodiments, the third embodiment of the present application provides a method for constructing a page using DSL, which is used to illustrate the specific construction process of the page. Figure 5 This is a flowchart of a method for constructing a page based on DSL provided in Embodiment 3 of the present application, such as Figure 5 As shown, the method provided in this embodiment includes the following steps.

[0182] S301. Check whether there is a view tree corresponding to the target DSL template in the memory.

[0183] When the display of the current page is triggered in the application, the identification information of one or more target DSL templates associated with the current page is obtained. The terminal device detects whether there is a view tree corresponding to the target DSL template in the view tree cache pool based on the identification information of the target DSL template.

[0184] There is a view tree corresponding to the target DSL template in the view tree cache pool, that is, there is a view tree corresponding to the target DSL template in the memory. When the view tree corresponding to the target DSL template exists in the memory, step S302 is executed; when the view tree corresponding to the target DSL template does not exist in the memory, step S306 is executed.

[0185] S302: Determine whether the page context in the view tree is the same as the context of the current page.

[0186] If the page context of the view tree is different from the context of the current page, execute step S303; if the page context of the view tree is the same as the context of the current page, execute step S304.

[0187] S303. Replace the page context of the view tree with the context of the current page to obtain the target view tree of the current page.

[0188] S304: Bind view data to each view in the target view tree to obtain a rendering tree.

[0189] Specifically, the terminal device searches for the expression corresponding to the target DSL template from the expression cache pool. If the expression corresponding to the target DSL template exists in the expression cache pool, the found expression is used to calculate the view data, and the calculation result is stored in each view of the target view tree. If the expression corresponding to the target DSL template does not exist in the expression cache pool, the class object corresponding to the target DSL template is obtained from the memory, the expression is extracted from the class object corresponding to the target DSL template, and the extracted expression is used to bind the view data.

[0190] S305: Bind the rendering tree to the current page, render the current page, and obtain a rendering result of the current page.

[0191] S306: Check whether there is a node tree corresponding to the target DSL template in the memory.

[0192] In this embodiment, hierarchical loading of DSL templates is adopted. When the view tree corresponding to the target DSL template does not exist in the memory, it is detected whether there is a node tree corresponding to the target DSL template in the node tree cache pool according to the identification information of the target DSL template.

[0193] When the node tree corresponding to the target DSL template exists in the memory, step S307 is executed; when the node tree corresponding to the target DSL template does not exist in the memory, step S308 is executed.

[0194] S307. Create a view tree according to the node tree corresponding to the target DSL template, and store the created view tree in memory.

[0195] The terminal device reads the node tree corresponding to the target DSL template from the node tree cache pool, and creates a view tree according to the node tree. In the process of creating the view tree, the terminal device can read the pre-created view from the view cache pool to improve the efficiency of creating the view tree. After creating the view tree, the view tree is stored in the view cache pool. After step S307, step S302 is executed.

[0196] S308: Detect whether there is a class object corresponding to the target DSL template in the memory.

[0197] When the node tree corresponding to the target DSL template does not exist in the memory, the terminal device detects whether the class object corresponding to the target DSL template exists in the class object cache pool according to the identification information of the target DSL template.

[0198] When the class object corresponding to the target DSL template exists in the memory, step S309 is executed; when the class object corresponding to the target DSL template does not exist in the memory, step S310 is executed.

[0199] S309: Create a node tree according to the class object corresponding to the target DSL template, and store the created node tree in memory.

[0200] The terminal device creates a node tree according to the class object corresponding to the target DSL template stored in the memory, and stores the created node tree in the node tree cache pool. After step S309, step S307 is executed.

[0201] S310: Detect whether there is original data corresponding to the target DSL template locally.

[0202] When the class object corresponding to the target DSL template does not exist in the memory, the terminal device detects whether the original data corresponding to the target DSL template is stored in the internal file of the APP according to the identification information of the target DSL template. When the original data corresponding to the target DSL template exists locally, step S311 is executed; when the original data corresponding to the target DSL template does not exist locally, step S312 is executed.

[0203] S311. Parse the original data corresponding to the target DSL template to obtain a class object.

[0204] The terminal device stores the class object corresponding to the target DSL template obtained through the analysis in the class object cache pool, and executes step S309 after step S311.

[0205] S312: Request the server for original data corresponding to the target DSL template, and store the requested original data locally.

[0206] When the original data corresponding to the target DSL template does not exist locally, the terminal device requests the original data corresponding to the target DSL template from the server according to the identification information of the target DSL template, and if the request for the original data is successful, the requested original data is stored in the local original data pool. After step S312, step S311 is executed.

[0207] In this embodiment, hierarchical loading of DSL templates is adopted, that is, the DSL templates are loaded in the following order: view tree, node tree, class object, local original data, server original data. The definition levels are from high to low: view tree, node tree, class object, local original data, server original data. The higher the level corresponding to the data, the less time and resources are required to load the DSL template, thereby improving the loading speed and efficiency of the current page, so that the rendering efficiency of the current page reaches or even exceeds the native performance of the Android application.

[0208] In order to better implement the method for constructing a page based on DSL in the embodiment of the present application, the embodiment of the present application also provides a device for constructing a page based on DSL. Figure 6 A schematic diagram of the structure of a device for constructing a page based on DSL provided in the fourth embodiment of the present application, such as Figure 6 As shown, the apparatus 100 for constructing a page based on DSL may include:

[0209] The detection module 11 is used to detect whether there is a view tree corresponding to the target domain specific language DSL template in the memory according to the identification information of the target domain specific language DSL template associated with the current page of the application, wherein the memory stores executable data of the loaded DSL template, and the executable data includes at least one of a view tree, a node tree and a class object corresponding to the DSL template, and the DSL template is a collection of description information of the user interface UI;

[0210] A creation module 12, configured to create a view tree corresponding to the target DSL template according to original data of the target DSL template or executable data of the target DSL template existing in the memory and save the view tree to the memory when the view tree corresponding to the target DSL template does not exist in the memory;

[0211] A replacement module 13 is used to replace the page context of the view tree corresponding to the target DSL template in the memory with the context of the current page to obtain the target view tree of the current page;

[0212] A data binding module 14 is used to obtain an expression corresponding to the target DSL template, and use the expression to bind view data to the view of the target view tree to obtain a rendering tree corresponding to the target view tree;

[0213] The rendering module 15 is used to bind the rendering tree to the current page, render the current page, and obtain a rendering result of the current page.

[0214] In some embodiments, the class object is obtained by parsing the original data of the DSL template, the node tree is created according to the class object, and the view tree is created according to the node tree;

[0215] The node tree is used to describe the association relationship of views in the user interface UI corresponding to the DSL template through a tree structure. Each node of the node tree corresponds to a view component, and the nodes of the node tree correspond to the nodes of the view tree one by one.

[0216] The memory also stores expressions corresponding to the DSL template.

[0217] In some embodiments, the executable data of the target DSL template in the memory includes a node tree and a class object corresponding to the target DSL template, and the creation module 13 is specifically used to:

[0218] Determine in sequence whether there is a node tree and a class object corresponding to the target DSL template in the memory;

[0219] When the node tree corresponding to the target DSL template exists in the memory, creating a view tree corresponding to the target DSL template according to the node tree corresponding to the target DSL template, and storing the view tree corresponding to the target DSL template in the memory;

[0220] When the class object corresponding to the target DSL template exists in the memory, a node tree and a view tree corresponding to the target DSL template are created according to the class object corresponding to the target DSL template, and expressions are extracted from the class object corresponding to the target DSL template, and the node tree, the view tree and the expressions corresponding to the target DSL template are stored in the memory;

[0221] When the class object corresponding to the target DSL template does not exist in the memory, original data of the target DSL template is obtained, a class object, a node tree, and a view tree corresponding to the target DSL template are created according to the original data of the target DSL template, expressions are extracted from the class object corresponding to the target DSL template, and the class object, the node tree, the view tree, and expressions corresponding to the target DSL template are stored in the memory.

[0222] In some embodiments, the replacement module 13 is specifically used for:

[0223] Determine whether the page context of the view tree corresponding to the target DSL template is the same as the context of the current page;

[0224] If the page context of the view tree corresponding to the target DSL template is the same as the context of the current page, determining that the view tree corresponding to the target DSL template is the target view tree;

[0225] If the page context of the view tree corresponding to the target DSL template is different from the context of the current page, the page context of the view tree corresponding to the target DSL template is replaced with the context of the current page to obtain the target view tree.

[0226] In some embodiments, the view tree corresponding to the target DSL template includes a proxy context, and the proxy context references the page context by means of a weak reference or a soft reference;

[0227] The replacement module 13 is specifically used for:

[0228] The page context referenced by the proxy context of the view tree corresponding to the target DSL template through weak reference or soft reference is replaced with the context of the current page.

[0229] In some embodiments, the loaded DSL template includes a preloaded DSL template and / or a real loaded DSL template, and the apparatus further includes a preloading module:

[0230] The preloading module is configured to predict a DSL template used by the application in the future when a preset first condition is met, use the DSL template used in the future as the preloaded DSL template, create executable data of the preloaded DSL template in an asynchronous manner, and store the executable data in the memory;

[0231] And / or, the creation module 12 is further used to create executable data of the DSL template associated with the other pages when constructing other pages for the application, and store the executable data in the memory, wherein the DSL template associated with the other pages is the actually loaded DSL template.

[0232] In some embodiments, the preloading module is specifically used to:

[0233] Obtaining original data of the preloaded DSL template;

[0234] Parsing the original data of the preloaded DSL template to obtain a class object corresponding to the preloaded DSL template, and storing the class object corresponding to the preloaded DSL template in the memory;

[0235] Creating a node tree corresponding to the preloaded DSL template according to the class object corresponding to the preloaded DSL template, and storing the node tree corresponding to the preloaded DSL template in the memory;

[0236] Creating a view tree corresponding to the preloaded DSL template according to the node tree corresponding to the preloaded DSL template, and storing the view tree corresponding to the preloaded DSL template in the memory;

[0237] Expressions are extracted from the class objects corresponding to the preloaded DSL template, and information of the extracted expressions is stored in the memory.

[0238] In some embodiments, the first condition includes one or more of the following conditions: detecting that the number of view trees stored in the memory is less than a first preset number, detecting that the application has idle threads, detecting that a preconfigured period has arrived, and detecting that the application is started.

[0239] In some embodiments, the creation module 12 is specifically used to:

[0240] Traversing the nodes of the node tree corresponding to the target DSL template, searching for a corresponding view from the view cache pool in the memory according to the view type of the node in the node tree corresponding to the target DSL template, wherein the view cache pool stores a plurality of pre-created views;

[0241] When the view corresponding to the current node is found from the view cache pool, the found view is added to the current node;

[0242] When the view corresponding to the current node is not found in the view cache pool, a view is created for the current node according to the view type of the current node.

[0243] In some embodiments, the apparatus further comprises:

[0244] A view creation module, used for creating a new view and storing it in the view cache pool when a preset second condition is met;

[0245] The second condition includes one or more of the following conditions: detecting that a preset page is started, detecting that an application thread is idle, detecting that an application is started, or detecting that the number of views in the view cache pool is less than a second preset number.

[0246] In some embodiments, the obtaining the original data of the target DSL template includes:

[0247] Reading the original data of the DSL template from an internal folder of the application stored locally according to the identification information of the target DSL template;

[0248] When the original data of the target DSL template is not stored in the internal folder of the application, requesting the original data of the target DSL template from the server according to the template name or storage address of the target DSL template;

[0249] receiving information of the target DSL template returned by the server, where the information of the target DSL template includes original data, a version number, and an information digest value of the target DSL template;

[0250] The original data of the target DSL template and the identification information of the target DSL template are stored in an internal folder of the application, where the identification information of the target DSL template includes the name, version number and information summary value of the target DSL template.

[0251] In some embodiments, the data binding module 14 is specifically used for:

[0252] Acquire an expression corresponding to the target DSL template from the memory, where the expression corresponding to the target DSL template is generated in a process of creating executable data of the target DSL template;

[0253] When the expression corresponding to the target DSL template cannot be obtained from the memory, a class object corresponding to the target DSL template is obtained from the memory, and an expression is extracted from the class object corresponding to the target DSL template to obtain the expression corresponding to the target DSL template, and the expression is stored in the expression corresponding to the target DSL template.

[0254] In some embodiments, the rendering tree is bound to the current page through a main thread of the application, and the rendering tree is obtained through an auxiliary thread of the application.

[0255] In some embodiments, the target DSL template includes three types of description information, wherein the first type of description information is used to describe the association relationship of views in the UI, the second type of description information is used to describe the style and layout of the views in the UI, and the third type of description information is used to describe the data binding logic of the views.

[0256] It should be understood that the device embodiment and the method embodiment may correspond to each other, and similar descriptions may refer to the method embodiment. To avoid repetition, they will not be described here.

[0257] The above describes the device 100 of the embodiment of the present application from the perspective of the functional module in conjunction with the accompanying drawings. It should be understood that the functional module can be implemented in hardware form, can be implemented by instructions in software form, and can also be implemented by a combination of hardware and software modules. Specifically, the steps of the method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit and / or software form instructions in the processor, and the steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or a combination of hardware and software modules in the decoding processor to perform. Optionally, the software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory, and completes the steps in the above method embodiment in conjunction with its hardware.

[0258] An embodiment of the present application also provides an electronic device. Figure 7 A structural diagram of an electronic device provided in Embodiment 5 of the present application, such as Figure 7 As shown, the electronic device 200 may include:

[0259] The memory 21 and the processor 22, the memory 21 is used to store the computer program and transmit the program code to the processor 22. In other words, the processor 22 can call and run the computer program from the memory 21 to implement the method in the embodiment of the present application.

[0260] For example, the processor 22 may be configured to execute the above method embodiments according to instructions in the computer program.

[0261] In some embodiments of the present application, the processor 22 may include but is not limited to: a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0262] In some embodiments of the present application, the memory 21 includes, but is not limited to, volatile memory and / or non-volatile memory. The non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus random access memory (Direct Rambus RAM, DR RAM).

[0263] In some embodiments of the present application, the computer program may be divided into one or more modules, which are stored in the memory 21 and executed by the processor 22 to complete the method provided by the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program in the electronic device.

[0264] like Figure 7As shown, the electronic device 200 may further include: a transceiver 23 , which may be connected to the processor 22 or the memory 21 .

[0265] The processor 22 may control the transceiver 23 to communicate with other devices, specifically, to send information or data to other devices, or to receive information or data sent by other devices. The transceiver 23 may include a transmitter and a receiver. The transceiver 23 may further include an antenna, and the number of antennas may be one or more.

[0266] Understandable, although Figure 7 Not shown, the electronic device 200 may also include a camera module, a wireless fidelity WIFI module, a positioning module, a Bluetooth module, a display, a controller, etc., which will not be repeated here.

[0267] It should be understood that the various components in the electronic device are connected via a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus and a status signal bus.

[0268] The present application also provides a computer storage medium on which a computer program is stored, and when the computer program is executed by a computer, the computer can perform the method of the above method embodiment. In other words, the present application embodiment also provides a computer program product containing instructions, and when the instructions are executed by a computer, the computer can perform the method of the above method embodiment.

[0269] The present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of the electronic device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the electronic device executes the corresponding process in the method embodiment, which will not be described here for brevity.

[0270] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the module is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.

[0271] The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. For example, each functional module in each embodiment of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0272] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for constructing a page based on DSL, characterized in that: include: According to identification information of a target domain specific language DSL template associated with a current page of the application, detecting whether a view tree corresponding to the target DSL template exists in a memory, wherein executable data of the loaded DSL template is stored in the memory, wherein the executable data includes at least one of a view tree, a node tree, and a class object corresponding to the DSL template, and the DSL template is a collection of description information of a user interface UI; When the view tree corresponding to the target DSL template does not exist in the memory, creating the view tree corresponding to the target DSL template according to the original data of the target DSL template or the executable data of the target DSL template existing in the memory and saving it in the memory; Replacing the page context of the view tree corresponding to the target DSL template in the memory with the context of the current page to obtain the target view tree of the current page; Obtain an expression corresponding to the target DSL template, use the expression to bind view data to the view of the target view tree, and obtain a rendering tree corresponding to the target view tree; The rendering tree is bound to the current page, and the current page is rendered to obtain a rendering result of the current page.

2. The method according to claim 1, characterized in that The class object is obtained by parsing the original data of the DSL template, the node tree is created according to the class object, and the view tree is created according to the node tree; The node tree is used to describe the association relationship of views in the user interface UI corresponding to the DSL template through a tree structure. Each node of the node tree corresponds to a view component, and the nodes of the node tree correspond to the nodes of the view tree one by one. The memory also stores expressions corresponding to the DSL template.

3. The method according to claim 2, characterized in that The executable data of the target DSL template existing in the memory includes a node tree and a class object corresponding to the target DSL template, and the creating a view tree corresponding to the target DSL template according to the original data of the target DSL template or the executable data of the target DSL template existing in the memory and saving the view tree to the memory includes: Determine in sequence whether there is a node tree and a class object corresponding to the target DSL template in the memory; When the node tree corresponding to the target DSL template exists in the memory, creating a view tree corresponding to the target DSL template according to the node tree corresponding to the target DSL template, and storing the view tree corresponding to the target DSL template in the memory; When the class object corresponding to the target DSL template exists in the memory, a node tree and a view tree corresponding to the target DSL template are created according to the class object corresponding to the target DSL template, and expressions are extracted from the class object corresponding to the target DSL template, and the node tree, the view tree and the expressions corresponding to the target DSL template are stored in the memory; When the class object corresponding to the target DSL template does not exist in the memory, original data of the target DSL template is obtained, a class object, a node tree, and a view tree corresponding to the target DSL template are created according to the original data of the target DSL template, expressions are extracted from the class object corresponding to the target DSL template, and the class object, the node tree, the view tree, and expressions corresponding to the target DSL template are stored in the memory.

4. The method according to any one of claims 1 to 3, characterized in that: The replacing the page context of the view tree corresponding to the target DSL template with the context of the current page to obtain the target view tree of the current page includes: Determine whether the page context of the view tree corresponding to the target DSL template is the same as the context of the current page; If the page context of the view tree corresponding to the target DSL template is the same as the context of the current page, determining that the view tree corresponding to the target DSL template is the target view tree; If the page context of the view tree corresponding to the target DSL template is different from the context of the current page, the page context of the view tree corresponding to the target DSL template is replaced with the context of the current page to obtain the target view tree.

5. The method according to any one of claims 1 to 3, characterized in that: The view tree corresponding to the target DSL template includes a proxy context, and the proxy context references the page context by means of weak reference or soft reference; The replacing the page context of the view tree corresponding to the target DSL template with the context of the current page includes: The page context referenced by the proxy context of the view tree corresponding to the target DSL template through weak reference or soft reference is replaced with the context of the current page.

6. The method according to any one of claims 1 to 3, characterized in that: The loaded DSL template includes a preloaded DSL template and / or a real loaded DSL template. Before detecting whether there is a view tree corresponding to the target DSL template in the memory, the method further includes: When a preset first condition is met, predicting a DSL template used by the application in the future, using the DSL template used in the future as a preloaded DSL template, creating executable data of the preloaded DSL template in an asynchronous manner, and storing the executable data in the memory; And / or, when constructing other pages for the application, creating executable data of the DSL template associated with the other pages and storing it in the memory, wherein the DSL template associated with the other pages is the actually loaded DSL template.

7. The method according to claim 6, characterized in that The step of creating the executable data of the preloaded DSL template and storing it in the memory includes: Obtaining original data of the preloaded DSL template; Parsing the original data of the preloaded DSL template to obtain a class object corresponding to the preloaded DSL template, and storing the class object corresponding to the preloaded DSL template in the memory; Creating a node tree corresponding to the preloaded DSL template according to the class object corresponding to the preloaded DSL template, and storing the node tree corresponding to the preloaded DSL template in the memory; Creating a view tree corresponding to the preloaded DSL template according to the node tree corresponding to the preloaded DSL template, and storing the view tree corresponding to the preloaded DSL template in the memory; Expressions are extracted from the class objects corresponding to the preloaded DSL template, and information of the extracted expressions is stored in the memory.

8. The method according to claim 7, characterized in that The first condition includes one or more of the following conditions: detecting that the number of view trees stored in the memory is less than a first preset number, detecting that the application has idle threads, detecting that a preconfigured period has arrived, and detecting that the application is started.

9. The method according to any one of claims 1 to 3, characterized in that: The view tree corresponding to the target DSL template is created in the following way: Traversing the nodes of the node tree corresponding to the target DSL template, searching for a corresponding view from the view cache pool in the memory according to the view type of the node in the node tree corresponding to the target DSL template, wherein the view cache pool stores a plurality of pre-created views; When the view corresponding to the current node is found from the view cache pool, the found view is added to the current node; When the view corresponding to the current node is not found in the view cache pool, a view is created for the current node according to the view type of the current node.

10. The method according to claim 9, characterized in that Also includes: When a preset second condition is met, a new view is created and stored in the view cache pool; The second condition includes one or more of the following conditions: detecting that a preset page is started, detecting that an application thread is idle, detecting that an application is started, or detecting that the number of views in the view cache pool is less than a second preset number.

11. The method according to claim 3, characterized in that The obtaining of the original data of the target DSL template includes: Reading the original data of the DSL template from an internal folder of the application stored locally according to the identification information of the target DSL template; When the original data of the target DSL template is not stored in the internal folder of the application, requesting the original data of the target DSL template from the server according to the template name or storage address of the target DSL template; receiving information of the target DSL template returned by the server, where the information of the target DSL template includes original data, a version number, and an information digest value of the target DSL template; The original data of the target DSL template and the identification information of the target DSL template are stored in an internal folder of the application, where the identification information of the target DSL template includes the name, version number and information summary value of the target DSL template.

12. The method according to any one of claims 1 to 3, characterized in that: The obtaining the expression corresponding to the target DSL template includes: Acquire an expression corresponding to the target DSL template from the memory, where the expression corresponding to the target DSL template is generated in a process of creating executable data of the target DSL template; When the expression corresponding to the target DSL template cannot be obtained from the memory, a class object corresponding to the target DSL template is obtained from the memory, and an expression is extracted from the class object corresponding to the target DSL template to obtain the expression corresponding to the target DSL template, and the expression is stored in the expression corresponding to the target DSL template.

13. The method according to any one of claims 1 to 3, characterized in that: The rendering tree is bound to the current page through the main thread of the application, and the rendering tree is obtained through the auxiliary thread of the application.

14. The method according to any one of claims 1 to 3, characterized in that: The target DSL template includes three types of description information, wherein the first type of description information is used to describe the association relationship of views in the UI, the second type of description information is used to describe the style and layout of the views in the UI, and the third type of description information is used to describe the data binding logic of the views.

15. A device for constructing a page based on DSL, characterized in that: include: a detection module, configured to detect whether a view tree corresponding to a target domain specific language DSL template exists in a memory according to identification information of the target domain specific language DSL template associated with a current page of the application, wherein executable data of the loaded DSL template is stored in the memory, wherein the executable data includes at least one of a view tree, a node tree, and a class object corresponding to the DSL template, and the DSL template is a collection of description information of a user interface UI; a creating module, configured to create a view tree corresponding to the target DSL template according to original data of the target DSL template or executable data of the target DSL template existing in the memory and save the view tree to the memory when the view tree corresponding to the target DSL template does not exist in the memory; A replacement module, used to replace the page context of the view tree corresponding to the target DSL template existing in the memory with the context of the current page, to obtain the target view tree of the current page; A data binding module, used to obtain an expression corresponding to the target DSL template, and use the expression to bind view data to the view of the target view tree to obtain a rendering tree corresponding to the target view tree; The rendering module is used to bind the rendering tree to the current page, render the current page, and obtain a rendering result of the current page.

16. An electronic device, characterized in that: include: A processor and a memory, the memory being used to store a computer program, and the processor being used to call and run the computer program stored in the memory to execute the method according to any one of claims 1 to 14.

17. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein the computer program causes a computer to execute the method according to any one of claims 1 to 14.

18. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 14 is implemented.