Method and device for improving H5 and Native communication performance
By obtaining the multi-dimensional scene complexity parameters of the H5 page to generate a scene fingerprint identification code, dynamically matching the communication protocol and optimizing message processing, the static protocol rigidity problem in the communication between H5 and Native is solved, the page fluency and stability are improved, and the memory usage and response time are reduced.
Patent Information
- Application Number
- CN202510574193.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-06
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2045-05-06
AI Technical Summary
In the existing technology, the static protocol for communication between H5 and Native is rigid, resulting in user experience issues such as page freezes, memory leaks, and CPU overloads, and it is impossible to dynamically adjust the communication protocol according to the complexity of the H5 page.
By obtaining the multi-dimensional scene complexity parameters of the H5 page, generating a scene fingerprint identification code, dynamically matching the communication protocol, and establishing a priority queue and WebView instance pool, it optimizes message processing and memory management.
It achieves dynamic adaptation of communication protocols, improves page fluency and stability, reduces memory usage and key information response time, and avoids performance bottlenecks of traditional static protocols in high-load scenarios.
Smart Images

Figure CN120602464A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of mobile application development, and in particular to a method and device for improving the communication performance between H5 and Native. Background Art
[0002] As mobile applications become increasingly complex, hybrid development architectures combining H5 (Hypertext Markup Language 5) and native applications (such as the native container + H5 business model) have become mainstream. H5-native communication relies on middleware such as JSBridge, but traditional solutions suffer from common issues such as static protocol rigidity, extensive resource management, and inefficient message scheduling. These issues can lead to user experience issues such as page lag, memory leaks, and CPU overload.
[0003] The current mainstream optimization solutions are: Protocol optimization uses common protocols such as JSON-RPC and WebSocket. However, the protocol types (such as synchronous / asynchronous, batch / single) are fixed and cannot be dynamically adjusted according to the real-time complexity of the H5 page (such as the number of nodes and script density). The current mainstream optimization solutions have the following technical problems: Existing solutions lack contextual awareness and fail to quantify the complexity of HTML5 pages (such as the number of nodes and rendering load). This results in the inability to dynamically adapt communication protocols (such as the batch transfer threshold). For example, a livestream HTML5 page experienced a sudden increase in script density (from 50KB to 200KB), and the original fixed protocol's 50ms batch transfer window remained unchanged, causing the lag rate to increase from 3% to 18%. Summary of the Invention
[0004] In view of this, the present application provides a method and apparatus for improving the communication performance between H5 and Native, so as to solve the problem of static protocol rigidity in the communication between H5 pages and Native, which causes page freezes.
[0005] In a first aspect, a method for improving the communication performance between H5 and Native is provided, which is applied to the Native side. The method includes: Get the first scene complexity parameters of the current H5 page, which include the number of nodes, script density, rendering load, interaction frequency, and network latency; generating a scene fingerprint identification code according to the first scene complexity parameter; Matching a preset communication protocol according to the scene fingerprint identification code; Communicate with the current H5 page according to the preset communication protocol; The amount of data during communication is obtained. If the amount of data is greater than a preset threshold, the second scenario complexity parameter of the current H5 page is obtained, and the preset communication protocol is rematched according to the second scenario complexity parameter.
[0006] Through the above technical solution, dynamic adaptation of the communication protocol can be achieved, and the multi-dimensional parameters of the page can be collected and hashed into a unique scene fingerprint to achieve fast pattern matching at the million level per second. When the single communication volume exceeds the preset threshold, secondary parameter collection is triggered to avoid the timeliness error of the initial fingerprint and the performance bottleneck of the traditional fixed protocol in high-load scenarios.
[0007] Optionally, the method further includes: A first scene complexity parameter threshold is preset to determine whether any parameter in the first scene complexity parameter is greater than the first scene complexity parameter threshold. When any parameter in the first scene complexity parameter is greater than the first scene complexity parameter threshold, the rendering method of the current H5 page is reselected.
[0008] Through the above technical solutions, a quantifiable performance warning mechanism is established, intelligent degradation and upgrade of the rendering engine is realized, and a flexible system for user experience is built, forming a continuous optimization closed loop. By building a safety threshold system for scene complexity parameters, the rendering engine is automatically switched when any parameter exceeds the standard (such as switching from WebView (web view) to a custom rendering kernel).
[0009] Optionally, generating a scene fingerprint identification code according to the first scene complexity parameter includes: The first scene complexity parameter is converted into a feature vector, and the feature vector is converted into a unique scene fingerprint identification code through a hash algorithm.
[0010] Through the above technical solution, a high-dimensional complexity feature space is constructed, the scene complexity parameters are mapped into feature vectors, and then a unique fingerprint identification code is generated through a hash algorithm. This algorithm improves the efficiency of protocol matching, establishes a mapping table between scene fingerprints and optimal protocols, supports dynamic updates at runtime, and provides a reliable basis for dynamic protocol selection.
[0011] Optionally, the method further includes: Create a WebView instance pool and load the current H5 page according to the WebView instance pool; Add a reference counter to each instance in the WebView instance pool and monitor the instance through the reference counter; When it is monitored that the current H5 page is destroyed, the memory occupied by the current H5 page is released to avoid memory leaks.
[0012] Through the above technical solutions, the life cycle management of WebView is transformed from discrete operations to systematic control, which can reduce the overhead of repeated creation / destruction of WebView, reduce memory usage, accurately manage memory, reduce memory leaks, and significantly improve the smoothness and stability of page switching.
[0013] Optionally, communicating with the current H5 page includes: Establish a priority queue for communicating with the current H5 page, assign priorities to messages according to message types, input the messages into the priority queue, and execute the messages in the priority queue in descending order of priority.
[0014] Through the above technical solutions, a message priority system is built (such as emergency events > user input > business logic > log reporting), which effectively reduces the response time of key information, avoids message disorder and blocking through the queue mechanism, improves communication throughput, effectively avoids page freezes or interaction delays caused by message blocking, and significantly improves the practicality and stability of the application.
[0015] Optionally, communicating with the current H5 page further includes: An initial time window is set, the initial time window is dynamically adjusted according to the CPU load to obtain a current time window, and the messages of the same priority in the current time window in the priority queue are merged to obtain batch instructions.
[0016] Through the above technical solution, the batch processing window is dynamically adjusted according to the CPU load (such as 500ms when idle and 50ms when heavily loaded), effectively improving the efficiency of message merging, reducing the number of communications in continuous interaction scenarios, and effectively balancing resource utilization and response speed.
[0017] Optionally, communicating with the current H5 page further includes: When a new message is received, the new message is compared with the target message currently being executed. If the priority of the new message is higher than that of the target message, the communication of the target message is interrupted, and the new message is inserted into the head of the priority queue and processed.
[0018] Through the above technical solutions, a priority preemption mechanism is built, allowing high-priority messages to interrupt low-priority messages, ensuring timely response to key operations (such as payment confirmation). In mixed load scenarios, the message processing order can be dynamically adjusted to effectively avoid key business delays caused by blocking low-priority messages.
[0019] In a second aspect of the present application, a system for improving the communication performance between H5 and Native is provided, including a parameter acquisition module, a fingerprint generation module, a protocol matching module, a communication module, and a communication monitoring module, wherein: A parameter collection module is configured to obtain the first scene complexity parameters of the current H5 page, which include the number of nodes, script density, rendering load, interaction frequency, and network latency; a fingerprint generation module configured to generate a scene fingerprint identification code according to a first scene complexity parameter; A protocol matching module configured to match a preset communication protocol according to a scene fingerprint identification code; A communication module configured to communicate with the current H5 page according to a preset communication protocol; The communication monitoring module is configured to obtain the amount of data during communication. If the amount of data obtained is greater than a preset threshold, the second scenario complexity parameter of the current H5 page is obtained, and the preset communication protocol is re-matched according to the second scenario complexity parameter.
[0020] In the third aspect of the present application, an electronic device is provided, including a processor, a memory, a user interface and a network interface, the memory is used to store instructions, the user interface and the network interface are both used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the electronic device performs any of the methods described above.
[0021] In a fourth aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores instructions. When the instructions are executed, any one of the methods described above is executed.
[0022] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: Dynamic adaptation of communication protocols is achieved, and multi-dimensional parameters of the page can be collected and hashed into unique scenario fingerprints, achieving fast pattern matching at the million-level per second, effectively improving the accuracy of protocol selection. When the single communication volume exceeds the preset threshold, secondary parameter collection and fingerprint update are triggered to avoid the timeliness error of the initial fingerprint, effectively breaking through the performance ceiling of traditional static protocols in high-load scenarios, and is particularly suitable for the dynamic resource scheduling needs of complex Web (network) applications (such as real-time collaboration tools and OA (Office Automation) applications). BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 This is an exemplary system architecture diagram of an embodiment of a method for improving H5 and Native communication performance or a system for improving H5 and Native communication performance applying the present application; Figure 2 This is a flowchart of a method for improving H5 and Native communication performance in an embodiment of the present application; Figure 3 yes Figure 2 A schematic flow chart of a specific implementation of step S202; Figure 4 This is another flowchart of a method for improving H5 and Native communication performance in an embodiment of the present application; Figure 5 This is a module diagram of a system for improving the communication performance between H5 and Native in an embodiment of the present application.
[0024] Explanation of the accompanying drawings: 100, system architecture; 101, first terminal device; 102, second terminal device; 103, third terminal device; 104, network; 105, server; 501, parameter acquisition module; 502, fingerprint generation module; 503, protocol matching module; 504, communication module; 505, communication monitoring module; 506, engine switching module; 507, pooling management module. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments.
[0026] In the description of the embodiments of this application, words such as "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "for example" or "for instance" in the embodiments of this application should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "for example" or "for instance" is intended to present the relevant concepts in a concrete manner.
[0027] In the description of the embodiments of the present application, the term "multiple" means two or more. For example, multiple systems refer to two or more systems, and multiple screen terminals refer to two or more screen terminals. In addition, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.
[0028] This embodiment discloses a method and device for improving the communication performance between H5 and Native. Figure 1A schematic diagram of an exemplary system architecture of an embodiment of a method for improving H5 and Native communication performance or a system for improving H5 and Native communication performance to which the present application can be applied is shown.
[0029] like Figure 1 As shown, system architecture 100 may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. Network 104 is a medium for providing communication links between terminal devices 101, 102, 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0030] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as model training applications, video recognition applications, web browser applications, social platform software, etc.
[0031] Terminal devices 101, 102, and 103 can be hardware or software. When terminal devices 101, 102, and 103 are hardware, they can be various electronic devices with display screens, including but not limited to smartphones, tablet computers, e-book readers, MP3 (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Group Audio Layer 3) players, MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Group Audio Layer 4) players, laptop computers, and desktop computers, etc. When terminal devices 101, 102, and 103 are software, they can be installed in the electronic devices listed above. They can be implemented as multiple software or software modules (for example, multiple software or software modules used to provide distributed services), or they can be implemented as a single software or software module. No specific limitation is made here.
[0032] When terminals 101, 102, and 103 are hardware, they may also be equipped with a video capture device. The video capture device may be any device capable of capturing video, such as a camera, a sensor, and the like. Users can use the video capture device on terminals 101, 102, and 103 to capture video.
[0033] The server 105 may be a server that provides various services, such as a background server that processes data displayed on the terminal devices 101, 102, and 103. The background server may analyze and process the received data, and may feed back the processing results (e.g., recognition results) to the terminal device.
[0034] It should be noted that a server can be either hardware or software. When a server is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When a server is software, it can be implemented as multiple software programs or software modules (for example, multiple software programs or software modules used to provide distributed services), or as a single software program or software module. This is not specifically limited here.
[0035] It should be understood that Figure 1 The number of terminal devices, networks, and servers in the above description is merely illustrative. Any number of terminal devices, networks, and servers may be used as needed. In particular, if target data does not need to be acquired remotely, the above system architecture may not include a network, but may instead include only terminal devices or servers.
[0036] Figure 2 This is a flow chart of the method for improving the communication performance between H5 and Native disclosed in the embodiment of this application, such as Figure 2 As shown, this embodiment includes: Step S201, obtain the first scene complexity parameters of the current H5 page, the first scene complexity parameters including the number of nodes, script density, rendering load, interaction frequency and network delay.
[0037] For example, the number of nodes can be obtained by traversing the DOM tree structure of the H5 page through the WebView API (Application Programming Interface) to count the number of nodes. For example, in Android development, the callback method of the WebViewClient can be used to obtain the DOM tree and count the nodes after the page is loaded. Script density can be obtained by analyzing the source code of the H5 page, counting the number of script tags and the number of script code lines, and calculating the script density. For example, regular expressions or HTML (Hyper Text Markup Language) parsing libraries can be used to extract script tags and codes. The rendering load can be obtained by monitoring the rendering time, CPU usage, GPU usage and other indicators of WebView to evaluate the rendering load. For example, these indicators can be obtained by using the performance detection tools provided by the Android system or third-party libraries. The interaction frequency can be obtained by recording the number and time interval of the user's interaction events with the H5 page (such as clicks, slides, zooms, etc.) to calculate the interaction frequency. For example, the user's interaction frequency can be obtained through the touch event listener of the WebView; Network latency can be obtained by sending a test data packet to the server where the H5 page is located, recording the round-trip time of the data packet, and obtaining the network latency. For example, the test data packet can be sent using the Android network programming interface (such as HttpURLConnection or OkHttp).
[0038] Step S202: Generate a scene fingerprint identification code according to the first scene complexity parameter.
[0039] For example, the first scene complexity parameters (number of nodes, script density, rendering load, interaction frequency, and network latency) obtained are arranged in a certain order to form a feature vector. For example, these parameters are normalized to form a five-dimensional vector, and then a hash algorithm (such as MD5 or SHA-256) is used to perform a hash operation on the feature vector to obtain a unique scene fingerprint identification code.
[0040] Step S203: matching a preset communication protocol according to the scene fingerprint identification code.
[0041] For example, a mapping table between scene fingerprint identification codes and preset communication protocols is pre-stored on the Native side. When a scene fingerprint identification code is generated, the corresponding preset communication protocol is found by querying the mapping table.
[0042] Step S204: communicate with the current H5 page according to a preset communication protocol.
[0043] For example, in the approval process of an OA application, with a large number of nodes and a high rendering load, a binary protocol, such as Protobuf or FlatBuffers, is needed to compress data and reduce serialization time. At the same time, a batch submission protocol can be used to merge multiple requests and reduce communication times.
[0044] Step S205, obtain the data volume per unit time during communication. If the data volume is greater than the preset threshold, obtain the second scenario complexity parameter of the current H5 page and re-match the preset communication protocol according to the second scenario complexity parameter.
[0045] Exemplarily, during the communication process, the data volume during communication is monitored in real time, for example, using a network traffic monitoring tool to obtain data volume information. When the data volume is greater than a preset threshold, the second scene complexity parameter of the current H5 page is obtained again, and the appropriate communication protocol is reselected according to the above method of generating a scene fingerprint identification code and matching the preset communication protocol.
[0046] Optional methods to improve the communication performance between H5 and Native include: A first scene complexity parameter threshold is preset to determine whether the target parameter is greater than the first scene complexity parameter threshold. When the target parameter is greater than the first scene complexity parameter, the rendering method of the current H5 page is reselected, and the target parameter is any parameter in the first scene complexity parameter.
[0047] For example, the reimbursement approval H5 page of an enterprise OA system contains 50+ fields (multi-level linkage drop-down boxes, attachment previews, calculation formulas), and the preset first scenario complexity parameter threshold is 1500. The enterprise employee opens the reimbursement form, and the full DOM rendering is performed (the fields can be edited directly). The current number of H5 page nodes is 800. The enterprise employee clicks "Add travel details" and dynamically adds 200 nodes (a total of 1000). The enterprise employee expands the "accommodation invoice" attachment and generates 300 preview nodes (a total of 1300). "Cross-departmental allocation" is checked and 500 nodes are dynamically inserted (a total of 1800). At this time, the number of H5 page nodes of 1800 is greater than the preset first scenario complexity parameter threshold of 1500, triggering Canvas rendering, static fields are converted to image backgrounds, and dynamic input boxes retain native components. The enterprise employee submits for approval, and the full DOM is submitted (including all node data).
[0048] Optionally, according to a preset communication protocol, communicating with the current H5 page also includes: Establish a priority queue that communicates with the current H5 page, assign priorities to messages according to message types, enter messages into the priority queue, and execute messages in the priority queue in descending order of priority.
[0049] For example, on the Android side, a message type enumeration class is defined, including four types: EMERGENCY (emergency event), USER_INPUT (user input), BUSINESS_LOGIC (business logic), and LOG_REPORT (log report). These are assigned priority weights of 4, 3, 2, and 1, respectively. A priority queue based on a max-heap data structure is created, with queue elements being message objects containing the fields: type (message type), content (message content), and timestamp (timestamp). When an H5 page triggers a communication request through prompt() or WebViewClient, the native layer parses the message type and encapsulates it into a message object. This object is then inserted into the priority queue based on the message type weight. The scheduler continuously monitors the queue and executes messages in descending order of weight. For example, a payment confirmation message (EMERGENCY) will be processed before a page scroll event (USER_INPUT).
[0050] Optionally, according to a preset communication protocol, communicating with the current H5 page also includes: An initial time window is set, and the initial time window is dynamically adjusted according to the CPU load to obtain the current time window. Messages of the same priority in the current time window in the priority queue are merged to obtain batch instructions.
[0051] For example, set the initial time window baseWindow to 500ms, the CPU load threshold highLoadThreshold to 80%, and the minimum window minWindow to 50ms. The current process CPU usage is obtained through ActivityManager with a sampling interval of 50ms. A sliding window algorithm is used to calculate the average load over the past second. When the average load is < 50%, the current time window currentWindow is maintained at 500ms. When 50% ≤ load < 80%, the window is linearly shortened using the formula currentWindow = baseWindow * (1-0.02 * (load-50)), where load is the CPU load. When the load is ≥ 80%, currentWindow is forced to 50ms. Within each currentWindow period, messages of the same priority in the queue are merged. For example, multiple LOG_REPORT messages can be merged into a single batch reporting instruction to reduce the number of I / O operations.
[0052] Optionally, according to a preset communication protocol, communicating with the current H5 page also includes: When a new message is received, the new message is compared with the currently executed target message. If the priority of the new message is higher than the target message, the communication of the target message is interrupted, and the new message is inserted into the head of the priority queue and processed.
[0053] For example, a message listener is set up in the WebView's evaluateJavascript callback interface. When a new message arrives, the preemption decision process is triggered, comparing the priority weight of the new message with the currently executing targetMessage. For example, if the new message is EMERGENCY (weight 4) and the targetMessage is BUSINESS_LOGIC (weight 2), preemption is triggered, immediately terminating the execution of the targetMessage (requiring transaction rollback or state preservation), reinserting it to the end of the priority queue, and inserting the new message to the head of the queue. The scheduler immediately executes the native operation corresponding to the message (such as calling the payment SDK (Software Development Kit)). When the interrupted targetMessage is re-executed, the status of dependent resources must be checked. For example, if the interrupted task is a file download, the download link validity must be verified before continuing.
[0054] Figure 3 yes Figure 2 A specific implementation flow diagram of step S202 is shown in FIG. Figure 3 As shown, generating a scene fingerprint identification code according to the first scene complexity parameter includes: Step S301: convert the first scene complexity parameter into a feature vector.
[0055] Exemplarily, the acquired first scene complexity parameters (number of nodes, script density, rendering load, interaction frequency, network delay) are arranged into a feature vector in a certain order, for example, {number of nodes: 100, script density: 50, rendering load: 70, interaction frequency: 30, network delay: 200}.
[0056] Step S302: convert the feature vector into a unique scene fingerprint identification code through a hash algorithm.
[0057] Exemplarily, for the above feature vector, a hash algorithm (such as MD5, SHA-256, etc.) is used to perform a hash operation on the feature vector to obtain a unique scene fingerprint identification code. For example, the above feature vector {number of nodes: 100, script density: 50, rendering load: 70, interaction frequency: 30, network delay: 200}, the unique scene fingerprint identification code "19e4cb765c55539e9426f1ba68560e9f" is obtained through a hash operation.
[0058] Figure 4 This is another flow chart of the method for improving the communication performance between H5 and Native in the embodiment of the present application. Figure 4 As shown, this embodiment includes: Step S401: Create a WebView instance pool and load the current H5 page according to the WebView instance pool.
[0059] For example, a WebView instance pool is created on the Native side, a certain number of WebView instances are created in advance, and a list is used to store these instances. When an employee clicks on a functional module in the OA system, such as leave approval, announcement viewing, etc., an available WebView instance is obtained from the WebView instance pool and the corresponding H5 page is loaded.
[0060] Step S402: Add a reference counter to each instance in the WebView instance pool, and monitor the instance through the reference counter.
[0061] For example, the "supplier contract approval" process of an enterprise's OA system involves three frequently switched H5 modules: the main approval page (containing 10+ fields), attachment preview (PDF / image), and historical version comparison (Table H5). When the main approval page opens an attachment, the current WebView instance is marked with {ref:2,modules:['contract','attachment']} (reference count +1). When returning to the main approval page, only the attachment module reference is reduced (count -1), and the contract module reference is retained (not released when the count is ≥1). When the approver clicks "Historical Version" on the contract page, the instance reference is expanded to {ref:3,modules:['contract','attachment','version']}. When returning step by step, the reference is decremented in the order of version, attachment, and contract to ensure that after the innermost module is closed, the outer layer can still reuse the instance.
[0062] Step S403: When it is monitored that the current H5 page is destroyed, the memory occupied by the current H5 page is released.
[0063] For example, in the "supplier invoice approval" process of a manufacturing OA system, a single invoice needs to be associated with 5-10 H5 attachments (PDF / Excel / picture). The financial staff clicks on the invoice attachment (H5 opens PDF), and returns to the approval form after viewing. The system detects that the attachment page is destroyed and immediately releases all memory of the WebView instance (including PDF rendering cache, WebView private heap). After filling in the approval opinion, click "Save Draft" and exit the page. The system determines that the current H5 is an "inactive process", releases memory but retains the draft data (stored in the local database). The device is forced to kill the background due to insufficient memory. After restarting OA, the system scans all historical H5 pages and performs memory cleanup on the destroyed pages (deleting residual WebView cache files).
[0064] Figure 5 This is a module diagram of a system for improving H5 and Native communication performance in an embodiment of the present application. Figure 5 As shown, the system includes: a parameter acquisition module 501, a fingerprint generation module 502, a protocol matching module 503, a communication module 504, and a communication monitoring module 505, wherein: The parameter acquisition module 501 is configured to obtain the first scene complexity parameters of the current H5 page, where the first scene complexity parameters include the number of nodes, script density, rendering load, interaction frequency, and network delay; A fingerprint generating module 502 is configured to generate a scene fingerprint identification code according to a first scene complexity parameter; The protocol matching module 503 is configured to match a preset communication protocol according to the scene fingerprint identification code; Communication module 504, configured to communicate with the current H5 page according to a preset communication protocol; The communication monitoring module 505 is configured to obtain the amount of data during communication. If the amount of data obtained is greater than a preset threshold, the second scenario complexity parameter of the current H5 page is obtained, and the preset communication protocol is re-matched according to the second scenario complexity parameter.
[0065] Optionally, the apparatus further includes an engine switching module 506 configured to: A first scene complexity parameter threshold is preset to determine whether the target parameter is greater than the first scene complexity parameter threshold. When the target parameter is greater than the first scene complexity parameter, the rendering method of the current H5 page is reselected, and the target parameter is any parameter in the first scene complexity parameter.
[0066] Optionally, the fingerprint generation module 502 is further configured to: Convert the first scene complexity parameter into a feature vector; The feature vector is converted into a unique scene fingerprint identification code through a hash algorithm.
[0067] Optionally, the system further includes a pooling management module 507 configured to: Create a WebView instance pool and load the current H5 page according to the WebView instance pool; Add a reference counter to each instance in the WebView instance pool and monitor the instance through the reference counter; When the current H5 page is destroyed, the memory occupied by the current H5 page will be released.
[0068] Optionally, the communication module 504 is further configured to: Establish a priority queue that communicates with the current H5 page, assign priorities to messages according to message types, enter messages into the priority queue, and execute messages in the priority queue in descending order of priority.
[0069] Optionally, the communication module 504 is further configured to: An initial time window is set, and the initial time window is dynamically adjusted according to the CPU load to obtain the current time window. Messages of the same priority in the current time window in the priority queue are merged to obtain batch instructions.
[0070] Optionally, the communication module 504 is further configured to: When a new message is received, the new message is compared with the currently executed target message. If the priority of the new message is higher than the target message, the communication of the target message is interrupted, and the new message is inserted into the head of the priority queue and processed.
[0071] It should be noted that the above embodiments provide systems that implement their functions using only the division of the above functional modules as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the system and method embodiments provided in the above embodiments are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0072] This embodiment also discloses an electronic device, which may include: at least one processor, at least one communication bus, a user interface, a network interface, and at least one memory.
[0073] The communication bus is used to realize the connection and communication between these components.
[0074] The user interface may include a display screen (Display) and a camera (Camera). Optional user interfaces may also include a standard wired interface and a wireless interface.
[0075] The network interface may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0076] The processor may include one or more processing cores. The processor utilizes various interfaces and circuits to connect various components within the server. It executes instructions, programs, code sets, or instruction sets stored in memory, and accesses data stored in memory to perform various server functions and process data. Optionally, the processor may be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing content displayed on the display; and the modem handles wireless communications. It is understood that the modem may also be implemented as a separate chip, rather than integrated into the processor.
[0077] The memory may include random access memory (RAM) or read-only memory (ROM). Optionally, the memory may include non-transitory computer-readable storage medium. The memory may be used to store instructions, programs, code, code sets, or instruction sets. The memory may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, sound playback function, image playback function, etc.), instructions for implementing each of the aforementioned method embodiments, etc.; the data storage area may store data related to each of the aforementioned method embodiments, etc. The memory may optionally be at least one storage device located remotely from the aforementioned processor. The memory, as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an application program for improving H5 and Native communication performance.
[0078] In an electronic device, the user interface is mainly used to provide an input interface for the user and obtain data input by the user; and the processor can be used to call an application stored in the memory for a method of improving the communication performance between H5 and Native. When executed by one or more processors, the electronic device executes one or more methods in the above embodiments.
[0079] It should be noted that for the aforementioned method embodiments, for simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required for this application.
[0080] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0081] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are merely schematic, such as the division of units, which is only a logical function division. In actual implementation, there may be other division methods, such as multiple units 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 service interface, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
[0082] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0083] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0084] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of this application, or the portion that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the method of this application. The aforementioned memory includes various media that can store program code, such as USB flash drives, mobile hard drives, magnetic disks, or optical disks.
[0085] The above is only an exemplary embodiment of the present disclosure and cannot be used to limit the scope of the present disclosure. That is, any equivalent changes and modifications made according to the teachings of the present disclosure are still within the scope of the present disclosure. After considering the disclosure of the specification, those skilled in the art will easily think of other embodiments of the present disclosure. This application is intended to cover any variations, uses or adaptive changes of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the technical field that are not recorded in the present disclosure. The description and examples are to be regarded as exemplary only, and the scope and spirit of the present disclosure are defined by the claims.
Claims
1. A method for improving the communication performance between H5 and Native, characterized in that: Applied to the Native side, the method includes: Obtain the first scene complexity parameters of the current H5 page, where the first scene complexity parameters include the number of nodes, script density, rendering load, interaction frequency, and network latency; generating a scene fingerprint identification code according to the first scene complexity parameter; Matching a preset communication protocol according to the scene fingerprint identification code; Communicate with the current H5 page according to the preset communication protocol; The data volume during communication is obtained. If the data volume is greater than a preset threshold, the second scenario complexity parameter of the current H5 page is obtained, and the preset communication protocol is rematched according to the second scenario complexity parameter.
2. The method for improving the communication performance between H5 and Native according to claim 1, characterized in that: The method further comprises: The first scene complexity parameter threshold is preset to determine whether the target parameter is greater than the first scene complexity parameter threshold. When the target parameter is greater than the first scene complexity parameter, the rendering method of the current H5 page is reselected, and the target parameter is any parameter in the first scene complexity parameter.
3. The method for improving the communication performance between H5 and Native according to claim 1, characterized in that: Generating a scene fingerprint identification code according to the first scene complexity parameter includes: Converting the first scene complexity parameter into a feature vector; The feature vector is converted into a unique scene fingerprint identification code through a hash algorithm.
4. The method for improving the communication performance between H5 and Native according to claim 1, characterized in that: The method further comprises: Create a WebView instance pool and load the current H5 page according to the WebView instance pool; Add a reference counter to each instance in the WebView instance pool, and monitor the instance through the reference counter; When it is monitored that the current H5 page is destroyed, the memory occupied by the current H5 page is released.
5. The method for improving the communication performance between H5 and Native according to claim 1, characterized in that: The communicating with the current H5 page includes: Establish a priority queue for communicating with the current H5 page, assign priorities to messages according to message types, input the messages into the priority queue, and execute the messages in the priority queue in descending order of priority.
6. The method for improving H5 and Native communication performance according to claim 5, characterized in that: The communicating with the current H5 page also includes: An initial time window is set, the initial time window is dynamically adjusted according to the CPU load to obtain a current time window, and messages of the same priority in the current time window in the priority queue are merged to obtain batch instructions.
7. The method for improving H5 and Native communication performance according to claim 5, characterized in that: The communicating with the current H5 page also includes: When a new message is received, the new message is compared with the target message currently being executed. If the priority of the new message is higher than that of the target message, the communication of the target message is interrupted, and the new message is inserted into the head of the priority queue and processed.
8. A system for improving the communication performance between H5 and Native, characterized by: It includes parameter acquisition module, fingerprint generation module, protocol matching module, communication module and communication monitoring module, among which: The parameter acquisition module is configured to obtain the first scene complexity parameter of the current H5 page, where the first scene complexity parameter includes the number of nodes, script density, rendering load, interaction frequency, and network delay; The fingerprint generation module is configured to generate a scene fingerprint identification code according to the first scene complexity parameter; The protocol matching module is configured to match a preset communication protocol according to the scene fingerprint identification code; The communication module is configured to communicate with the current H5 page according to the preset communication protocol; The communication monitoring module is configured to obtain the amount of data during communication. If the amount of data is greater than a preset threshold, the second scenario complexity parameter of the current H5 page is obtained, and the preset communication protocol is re-matched according to the second scenario complexity parameter.
9. An electronic device, characterized in that: The electronic device comprises a processor, a memory, a user interface and a network interface, wherein the memory is used to store instructions, the user interface and the network interface are both used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the electronic device executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed, the method according to any one of claims 1 to 7 is executed.
Citation Information
Patent Citations
Page parameter acquisition method, terminal equipment and medium
CN110298000A
Method for dynamically adjusting encoder parameters based on scene complexity
CN110519571A
H5 page and native APP interaction method and device and storage medium
CN111767052A
Cross-end meta-universe interaction system and method and storage medium
CN115826809A
Communication method and device for Html5 page and native application module
CN117520000A