Method and apparatus for improving H5 and native communication performance
By obtaining multi-dimensional scene complexity parameters of the H5 page to generate scene fingerprint identification codes and dynamically matching communication protocols, the problem of static protocol rigidity in H5-Native communication is solved, improving page smoothness and stability, and reducing memory leaks and resource waste.
Patent Information
- Application Number
- CN202510574193.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-06
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2045-05-06
AI Technical Summary
In existing technologies, the static and rigid communication protocols between H5 and Native pages cause page lag and cannot dynamically adjust the communication protocol according to the real-time complexity of the H5 page, resulting in performance bottlenecks and user experience issues.
By acquiring multi-dimensional scene complexity parameters of H5 pages, a scene fingerprint identification code is generated, communication protocols are dynamically matched, and secondary parameter collection is triggered under high load to establish a performance early warning mechanism and priority queue, thereby optimizing message processing.
It achieves dynamic adaptation of communication protocols, improves page smoothness and stability, reduces memory leaks and resource waste, and improves the response speed of critical information.
Smart Images

Figure CN120602464B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of mobile application development, and in particular to a method and device for improving H5 and Native communication performance. BACKGROUND
[0002] With the complication of mobile application functions, H5 (HyperText Markup Language 5) and Native (native application) hybrid development architecture (such as Native container + H5 business mode) has become mainstream. H5-Native communication relies on JSBridge and other middleware, but the traditional scheme has common problems such as static protocol rigidity, extensive resource management, and inefficient message scheduling, resulting in user experience problems such as page lag, memory leakage, and CPU overload.
[0003] The current mainstream optimization scheme mainly includes:
[0004] Protocol optimization, using JSON-RPC, WebSocket, and other general protocols, but the protocol type (such as synchronous / asynchronous, batch / single) is fixed and cannot be dynamically adjusted according to the real-time complexity of the H5 page (such as node number, script density);
[0005] The current mainstream optimization scheme has the following technical problems:
[0006] Lack of scene awareness, existing schemes do not quantify the complexity of the H5 page (such as node number, rendering load, etc.), resulting in communication protocols (such as batch transmission threshold) that cannot be dynamically adapted. For example, a certain live H5 page has a sudden increase in script density (from 50KB to 200KB), and the batch transmission window (50ms) of the original fixed protocol is not adjusted, resulting in a lag rate from 3% to 18%. SUMMARY
[0007] Therefore, the present application provides a method and device for improving H5 and Native communication performance to solve the problem of static protocol rigidity between H5 page and Native, resulting in page lag.
[0008] In a first aspect, a method for improving H5 and Native communication performance is provided, applied to the Native end, which includes:
[0009] Obtaining a first scene complexity parameter of a current H5 page, the first scene complexity parameter including node number, script density, rendering load, interaction frequency, and network delay;
[0010] Generating a scene fingerprint identification code according to the first scene complexity parameter;
[0011] Matching a preset communication protocol according to the scene fingerprint identification code;
[0012] communicate with the current H5 page according to the preset communication protocol;
[0013] acquire a data amount during communication, and if the data amount is greater than a preset threshold, acquire a second scene complexity parameter of the current H5 page, and re-match the preset communication protocol according to the second scene complexity parameter.
[0014] Through the above technical solutions, dynamic adaptation of the communication protocol is achieved, multi-dimensional parameters of a page are collected, multi-dimensional parameters are hashed into a unique scene fingerprint, and rapid mode matching of millions per second is achieved. When a single communication amount exceeds a preset threshold, secondary parameter collection is triggered, time effectiveness error of an initial fingerprint is avoided, and a performance bottleneck of a traditional fixed protocol in a high-load scene is avoided.
[0015] Optionally, the method further includes:
[0016] presetting a first scene complexity parameter threshold, determining whether any parameter in the first scene complexity parameter is greater than the first scene complexity parameter threshold, and when any parameter in the first scene complexity parameter is greater than the first scene complexity parameter threshold, re-selecting a rendering mode of the current H5 page.
[0017] Through the above technical solutions, a quantifiable performance early warning mechanism is established, intelligent degradation and upgrading of a rendering engine are achieved, a user experience discretionary system is constructed, a continuous optimization closed loop is formed, and when any parameter exceeds a standard, a rendering engine is automatically switched (such as from WebView (web page view) to a custom rendering kernel).
[0018] Optionally, generating a scene fingerprint identification code according to the first scene complexity parameter includes:
[0019] converting the first scene complexity parameter into a feature vector, and converting the feature vector into a unique scene fingerprint identification code through a hash algorithm.
[0020] Through the above technical solutions, a high-dimensional complexity feature space is constructed, a scene complexity parameter is mapped into a feature vector, and then a unique fingerprint identification code is generated through a hash algorithm. The algorithm improves protocol matching efficiency, establishes a scene fingerprint and optimal protocol mapping table, supports runtime dynamic updating, and provides a reliable basis for dynamic protocol selection.
[0021] Optionally, the method further includes:
[0022] creating a WebView instance pool, and loading the current H5 page according to the WebView instance pool;
[0023] adding a reference counter to each instance in the WebView instance pool, the instance being monitored by the reference counter;
[0024] when the current H5 page is destroyed, the memory occupied by the current H5 page is released, avoiding memory leakage.
[0025] Through the above technical solutions, the life cycle management of WebView is converted from discrete operation to systematic control, which can reduce the overhead of repeated creation / destruction of WebView, reduce memory occupation, accurately manage memory, reduce memory leakage, and significantly improve the smoothness and stability of page switching.
[0026] Optionally, the communication with the current H5 page includes:
[0027] A priority queue for communication with the current H5 page is established, the messages are assigned priorities according to message types, the messages are input into the priority queue, and the messages in the priority queue are executed in order from high to low priority.
[0028] Through the above technical solutions, a message priority system (such as emergency > user input > business logic > log reporting) is constructed, which effectively reduces the response time of critical information, avoids message disorder and blocking through the queue mechanism, improves communication throughput, effectively avoids page lag or interaction delay caused by message blocking, and significantly improves the practicality and stability of the application.
[0029] Optionally, the communication with the current H5 page further includes:
[0030] An initial time window is set, the initial time window is dynamically adjusted according to 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.
[0031] Through the above technical solutions, the batch processing window is dynamically adjusted according to CPU load (such as 500ms when idle and 50ms when high load), which effectively improves the message merging efficiency, reduces the communication frequency in continuous interaction scenarios, and effectively balances resource utilization and response speed.
[0032] Optionally, the communication with the current H5 page further includes:
[0033] When a new message is received, the new message is compared with a 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, the new message is inserted into the head of the priority queue and processed.
[0034] By the above technical solution, the priority preemption mechanism is constructed, the high-priority message is allowed to interrupt the low-priority message, the timely response of critical operations (such as payment confirmation) is ensured, in a mixed load scenario, the message processing order can be dynamically adjusted, and the key business delay caused by the blocking of low-priority messages can be effectively avoided.
[0035] In a second aspect of the present application, a system for improving H5 and Native communication performance is provided, comprising a parameter acquisition module, a fingerprint generation module, a protocol matching module, a communication module, and a communication monitoring module, wherein:
[0036] The parameter acquisition module is configured to obtain a first scene complexity parameter of the current H5 page, and the first scene complexity parameter includes the number of nodes, the script density, the rendering load, the interaction frequency, and the network delay.
[0037] The fingerprint generation module is configured to generate a scene fingerprint identification code according to the first scene complexity parameter.
[0038] The protocol matching module is configured to match a preset communication protocol according to the scene fingerprint identification code.
[0039] The communication module is configured to communicate with the current H5 page according to the preset communication protocol.
[0040] The communication monitoring module is configured to obtain the data amount during communication, and if the obtained data amount is greater than a preset threshold, obtain a second scene complexity parameter of the current H5 page, and match the preset communication protocol again according to the second scene complexity parameter.
[0041] In a third aspect of the present application, an electronic device is provided, comprising a processor, a memory, a user interface, and a network interface, the memory is configured to store instructions, the user interface and the network interface are configured to communicate with other devices, and the processor is configured to execute the instructions stored in the memory to enable the electronic device to perform the method described in any one of the above aspects.
[0042] In a fourth aspect of the present application, a computer readable storage medium is provided, and the computer readable storage medium stores instructions, when the instructions are executed, the method described in any one of the above aspects is performed.
[0043] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:
[0044] The dynamic adaptation of the communication protocol can collect multi-dimensional parameters of the page, hash the multi-dimensional parameters into a unique scene fingerprint, realize the rapid mode matching of millions per second, effectively improve the accuracy of protocol selection, trigger secondary parameter collection and fingerprint update when the single communication volume exceeds the preset threshold, avoid the timeliness error of the initial fingerprint, effectively break through the performance ceiling of the traditional static protocol in the high load scene, and is particularly suitable for the dynamic resource scheduling demand of complex Web (network) application (such as real-time collaboration tools, OA (Office Automation, office automation) application). BRIEF DESCRIPTION OF DRAWINGS
[0045] Figure 1 is an exemplary system architecture diagram of an embodiment of the application, which is a method for improving H5 and Native communication performance or a system for improving H5 and Native communication performance;
[0046] Figure 2 is a flowchart of an embodiment of the application, which is a method for improving H5 and Native communication performance;
[0047] Figure 3 is Figure 2 is a specific embodiment flowchart of step S202 in
[0048] Figure 4 is another flowchart of an embodiment of the application, which is a method for improving H5 and Native communication performance;
[0049] Figure 5 is a module diagram of an embodiment of the application, which is a system for improving H5 and Native communication performance.
[0050] Reference signs: 100, system architecture; 101, first terminal device; 102, second terminal device; 103, third terminal device; 104, network; 105, server; 501, parameter collection 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
[0051] In order for those skilled in the art to better understand the technical solutions in the specification, the technical solutions in the specification will be described clearly and completely in conjunction with the drawings in the embodiments of the specification. Obviously, the described embodiments are only a part of the embodiments of the application, not all the embodiments.
[0052] In the description of the embodiments of the present application, the words "for example" or "such as" are used to represent that an example, an illustration or an exposition. Any embodiment or design scheme described as "for example" or "such as" in the embodiments of the present application should not be interpreted as more preferred or more advantageous than other embodiments or design schemes. In fact, the words "for example" or "such as" are intended to present the relevant concept in a specific manner.
[0053] In the description of the embodiments of the present application, the term "a plurality of" means two or more. For example, a plurality of systems means two or more systems, and a plurality of screen terminals means two or more screen terminals. In addition, the terms "first" and "second" are only used for description purposes and should not be interpreted or implied to indicate or imply relative importance or implicitly indicate the indicated technical features. Therefore, the features defined with "first" and "second" can explicitly or implicitly include one or more of the features. The terms "include", "contain", "have" and their variants mean "including but not limited to", unless otherwise specifically emphasized.
[0054] The embodiments disclose a method and device for improving H5 and Native communication performance, Figure 1 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 to which the present application can be applied is shown.
[0055] As shown in Figure 1 The system architecture 100 can include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104 and a server 105. The network 104 is used as a medium to provide communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 can include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0056] A user can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 101, 102, 103, such as model training applications, video recognition applications, web browser applications, social platform software, etc.
[0057] The terminal devices 101, 102, and 103 can be hardware or software. When the terminal devices 101, 102, and 103 are hardware, they can be various electronic devices with a display screen, including but not limited to a smart phone, a tablet computer, an e-book reader, an MP3 (Moving Picture Experts Group Audio Layer III) player, an MP4 (Moving Picture Experts Group Audio Layer IV) player, a laptop computer, a desktop computer, and the like. When the terminal devices 101, 102, and 103 are software, they can be installed in the above-listed electronic devices. They can be implemented as multiple software or software modules (for example, multiple software or software modules for providing distributed services) or as a single software or software module. No specific limitation is made herein.
[0058] When the terminal 101, 102, or 103 is hardware, a video capture device can also be installed thereon. The video capture device can be various devices capable of capturing video, such as a camera, a sensor, and the like. A user can capture video by using the video capture device on the terminal 101, 102, or 103.
[0059] The server 105 can be a server providing various services, for example, a background server for processing data displayed on the terminal devices 101, 102, and 103. The background server can analyze and process received data, and can feed back the processing result (for example, a recognition result) to the terminal device.
[0060] It should be noted that the server can be hardware or software. When the server is hardware, it can be implemented as a distributed server cluster composed of multiple servers or as a single server. When the server is software, it can be implemented as multiple software or software modules (for example, multiple software or software modules for providing distributed services) or as a single software or software module. No specific limitation is made herein.
[0061] It should be understood that Figure 1 The number of terminal devices, networks, and servers in the system architecture is merely illustrative. According to implementation needs, there can be any number of terminal devices, networks, and servers. In particular, in the case where target data does not need to be acquired from a remote location, the above system architecture can not include a network, but only include a terminal device or a server.
[0062] Figure 2 is a flowchart of a method for improving the communication performance between H5 and Native disclosed by an embodiment of the present application, as shown in Figure 2As shown, the present embodiment includes:
[0063] In step S201, a first scene complexity parameter of a current H5 page is acquired, and the first scene complexity parameter includes a node number, a script density, a rendering load, an interaction frequency, and a network delay.
[0064] For example, the node number can be acquired by traversing a DOM tree structure of the H5 page through an API (Application Programming Interface) of the WebView, and counting the number of nodes. For example, in Android development, a callback method of the WebViewClient can be used to acquire the DOM tree and count the nodes after the page is loaded.
[0065] The script density can be acquired by analyzing the source code of the H5 page, counting the number of script tags and the number of lines of script code, and calculating the script density. For example, a regular expression or an HTML (Hyper Text Markup Language) parsing library can be used to extract the script tags and code.
[0066] The rendering load can be acquired by monitoring the rendering time, CPU usage, GPU usage, and other indicators of the WebView to evaluate the rendering load. For example, a performance detection tool provided by the Android system or a third-party library can be used to acquire these indicators.
[0067] The interaction frequency can be acquired by recording the number and time interval of user interaction events (such as clicking, sliding, zooming, etc.) with the H5 page, and calculating the interaction frequency. For example, a touch event listener of the WebView can be used to acquire the interaction frequency of the user.
[0068] The network delay can be acquired 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 delay. For example, the network programming interface (such as HttpURLConnection or OkHttp) of the Android can be used to send the test data packet.
[0069] In step S202, a scene fingerprint identification code is generated according to the first scene complexity parameter.
[0070] For example, the acquired first scene complexity parameters (node number, script density, rendering load, interaction frequency, and network delay) are arranged in a certain order to form a feature vector. For example, after normalization, these parameters form a five-dimensional vector, and then a hash algorithm (such as MD5, SHA-256, etc.) is used to perform hash operation on the feature vector to obtain a unique scene fingerprint identification code.
[0071] Step S203, matching the preset communication protocol according to the scene fingerprint identification code.
[0072] Exemplarily, a mapping table of a scene fingerprint identification code and a preset communication protocol is pre-stored in the Native end, and when the scene fingerprint identification code is generated, the corresponding preset communication protocol is found by querying the mapping table.
[0073] Step S204, communicating with the current H5 page according to the preset communication protocol.
[0074] Exemplarily, in the approval process of the OA application, the number of nodes is large, the rendering load is high, and a binary protocol such as Protobuf or FlatBuffers is needed to compress data to reduce serialization time. At the same time, a batch submission protocol is used to combine multiple requests to reduce the number of communications.
[0075] Step S205, obtaining the data volume in a unit of time during communication, and if the data volume is greater than a preset threshold, obtaining a second scene complexity parameter of the current H5 page, and re-matching the preset communication protocol according to the second scene complexity parameter.
[0076] Exemplarily, in the communication process, the data volume during communication is monitored in real time, for example, a network flow monitoring tool is used to obtain the data volume information, and when the data volume is greater than the preset threshold, a second scene complexity parameter of the current H5 page is obtained again, and the above method of generating a scene fingerprint identification code and matching a preset communication protocol is used to re-select a suitable communication protocol.
[0077] Optionally, the method for improving the communication performance between H5 and Native further comprises:
[0078] A preset first scene complexity parameter threshold is used to determine whether the target parameter is greater than the first scene complexity parameter threshold, and when the target parameter is greater than the first scene complexity parameter, the rendering mode of the current H5 page is re-selected, and the target parameter is any parameter in the first scene complexity parameter.
[0079] Exemplarily, the reimbursement approval H5 page of an OA system of an enterprise contains 50+ fields (multi-level linkage drop-down box, attachment preview, calculation formula), a preset first scene complexity parameter threshold is 1500, an employee of the enterprise opens the reimbursement form, at this time, full-amount DOM rendering is performed (the fields can be directly edited), the current H5 page node number is 800, the employee clicks "add travel details", 200 nodes are dynamically added (total 1000), the employee expands the "accommodation invoice" attachment, 300 preview nodes are generated (total 1300), checks "cross-departmental allocation", 500 nodes are dynamically inserted (total 1800), at this time, the H5 page node number 1800 is greater than the preset first scene complexity parameter threshold 1500, Canvas rendering is triggered, the static fields are converted into picture backgrounds, the dynamic input boxes retain the original components, the employee submits the approval, and full-amount DOM submission (containing all node data) is performed.
[0080] Optionally, the communication with the current H5 page according to the preset communication protocol further includes:
[0081] A priority queue for communication with the current H5 page is established, messages are assigned priorities according to message types, the messages are input into the priority queue, and the messages in the priority queue are executed in order from high to low priority.
[0082] Exemplarily, a message type enumeration class is defined on the Android side, containing four types of EMERGENCY (emergency event), USER_INPUT (user input), BUSINESS_LOGIC (business logic), and LOG_REPORT (log reporting), which are respectively assigned priority weight values 4, 3, 2, and 1, a priority queue based on a maximum heap data structure is created, the queue elements are message objects, containing fields: type (message type), content (message content), and timestamp (timestamp), when the H5 page triggers a communication request through prompt() or WebViewClient, the Native layer parses the message type and encapsulates it into a message object, inserts the message object into the priority queue according to the message type weight value, and the dispatcher continuously listens to the queue and takes out the messages in order from large to small weight value to execute. For example, a payment confirmation message (EMERGENCY) is processed in priority to a page scrolling event (USER_INPUT).
[0083] Optionally, the communication with the current H5 page according to the preset communication protocol further includes:
[0084] An initial time window is set, the initial time window is dynamically adjusted according to CPU load to obtain a current time window, and messages of the same priority in the priority queue within the current time window are merged to obtain batch instructions.
[0085] Exemplarily, an initial time window baseWindow=500ms, a CPU load threshold highLoadThreshold=80%, a minimum window minWindow=50ms are set, the current process CPU usage is obtained through ActivityManager, the sampling interval is 50ms, the sliding window algorithm is used to calculate the average load in the last 1 second, when the average load<50%, the current time window currentWindow=500ms is maintained, when 50%≤load<80%, the window is linearly shortened according to the formula currentWindow=baseWindow*(1-0.02*(load-50)), wherein load is the CPU load, when load≥80%, currentWindow=50ms is forced, and in each currentWindow period, the messages of the same priority in the queue are merged. For example, multiple LOG_REPORT messages are merged into a single batch reporting instruction, and the number of IO operations is reduced.
[0086] Optionally, the communication with the current H5 page according to the preset communication protocol further includes:
[0087] When a new message is received, the new message is compared with a 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, the new message is inserted into the head of the priority queue and processed.
[0088] Exemplarily, a message listener is set in the evaluateJavascript callback interface of the WebView, when a new message arrives, the preemption judgment process is triggered, and the priority weight values of the new message and a target message currently being executed targetMessage are compared. For example, when the new message is EMERGENCY (weight 4) and the targetMessage is BUSINESS_LOGIC (weight 2), preemption is triggered, the execution of the targetMessage is immediately terminated (transaction rollback or state saving needs to be supported), the targetMessage is reinserted into the tail of the priority queue, the new message is inserted into the head of the queue, and the dispatcher immediately executes the Native operation corresponding to the message (such as calling a payment SDK (Software Development Kit)). When the targetMessage interrupted is re-executed, the dependent resource state needs to be checked. For example, if the interrupted targetMessage is a file download task, the download link validity needs to be checked before continuing.
[0089] Figure 3 is Figure 2 A specific embodiment flowchart of step S202 is shown in FIG. 2B. Figure 3As shown, generating the scene fingerprint code according to the first scene complexity parameter comprises:
[0090] Step S301, converting the first scene complexity parameter into a feature vector.
[0091] Exemplarily, the acquired first scene complexity parameters (node number, script density, rendering load, interaction frequency, network delay) are arranged into a feature vector in a certain order, for example, {node number: 100, script density: 50, rendering load: 70, interaction frequency: 30, network delay: 200}.
[0092] Step S302, converting the feature vector into a unique scene fingerprint code through a hash algorithm.
[0093] Exemplarily, for the above feature vector, a hash algorithm (such as MD5, SHA-256, etc.) is used to perform hash operation on the feature vector to obtain a unique scene fingerprint code. For example, the above feature vector {node number: 100, script density: 50, rendering load: 70, interaction frequency: 30, network delay: 200} is obtained through hash operation to obtain a unique scene fingerprint code “19e4cb765c55539e9426f1ba68560e9f”.
[0094] Figure 4 is another flowchart of the method for improving the communication performance between H5 and Native in the embodiment of the present application, as shown in Figure 4 the embodiment comprises:
[0095] Step S401, creating a WebView instance pool and loading the current H5 page according to the WebView instance pool.
[0096] Exemplarily, 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 a certain functional module in the OA system, such as leave approval, announcement viewing, etc., a usable WebView instance is obtained from the WebView instance pool, and the corresponding H5 page is loaded.
[0097] Step S402, adding a reference counter to each instance in the WebView instance pool, and monitoring the instance through the reference counter.
[0098] Exemplarily, the "supplier contract approval" process of an OA system of an enterprise involves three high-frequency switching H5 modules of a main approval page (containing 10+ fields), an attachment preview (PDF / picture), and a historical version comparison (table H5). When the main approval page opens the 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 reference of the attachment module is reduced (count -1), and the reference of the contract module is retained (count ≥1, not released). 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 reduced in the order of version, attachment, and contract. After the innermost module is closed, the outer layer can still reuse the instance.
[0099] In step S403, when it is monitored that the current H5 page is destroyed, the memory occupied by the current H5 page is released.
[0100] Exemplarily, the "supplier invoice approval" process of an OA system of a manufacturing enterprise involves 5-10 H5 attachments (PDF / Excel / picture) associated with a single invoice. When the financial personnel click the invoice attachment (H5 opens PDF), the system detects the destruction of the attachment page and immediately releases all the memory of the WebView instance (including PDF rendering cache and WebView private heap). After filling in the approval opinion and clicking "save as draft" and exiting the page, the system judges that the current H5 is "non-active process", releases the memory but retains the draft data (stored in the local database). Due to insufficient memory, the device forcibly kills the background, and after restarting the OA, the system scans all historical H5 pages and performs memory cleaning (deletes residual WebView cache files) on the destroyed pages.
[0101] Figure 5 is a module schematic diagram of the system for improving the communication performance between H5 and Native in the embodiment of the application, as shown in Figure 5 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.
[0102] The parameter acquisition module 501 is configured to acquire a first scene complexity parameter of the current H5 page. The first scene complexity parameter includes node number, script density, rendering load, interaction frequency, and network delay.
[0103] The fingerprint generation module 502 is configured to generate a scene fingerprint identification code according to the first scene complexity parameter.
[0104] The protocol matching module 503 is configured to match a preset communication protocol according to the scene fingerprint identification code.
[0105] The communication module 504 is configured to communicate with the current H5 page according to the preset communication protocol.
[0106] The communication monitoring module 505 is configured to acquire a data amount during communication, and if the acquired data amount is greater than a preset threshold, acquire a second scene complexity parameter of the current H5 page, and re-match the preset communication protocol according to the second scene complexity parameter.
[0107] Optionally, the apparatus further comprises an engine switching module 506 configured to:
[0108] preset a first scene complexity parameter threshold, judge whether a target parameter is greater than the first scene complexity parameter threshold, and when the target parameter is greater than the first scene complexity parameter, reselect a rendering mode of the current H5 page, and the target parameter is any parameter in the first scene complexity parameter.
[0109] Optionally, the fingerprint generation module 502 is further configured to:
[0110] convert the first scene complexity parameter into a feature vector;
[0111] convert the feature vector into a unique scene fingerprint identification code through a hash algorithm.
[0112] Optionally, the system further comprises a pooling management module 507 configured to:
[0113] create a WebView instance pool, and load the current H5 page according to the WebView instance pool;
[0114] add a reference counter to each instance in the WebView instance pool, and monitor the instance through the reference counter;
[0115] when the current H5 page is monitored to be destroyed, release the memory occupied by the current H5 page.
[0116] Optionally, the communication module 504 is further configured to:
[0117] establish a priority queue for communication 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 order from high to low priority.
[0118] Optionally, the communication module 504 is further configured to:
[0119] 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 a batch instruction.
[0120] Optionally, the communication module 504 is further configured to:
[0121] When a new message is received, the new message is compared with a target message 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, the new message is inserted into the head of the priority queue and processed.
[0122] It should be noted that: the system provided in the above examples, when realizing its function, only the above-mentioned division of each functional module is exemplified, and in actual application, the above-mentioned functions can be completed by different functional modules according to needs, that is, the internal structure of the device is 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 examples belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0123] The embodiment also discloses an electronic device, which can comprise: at least one processor, at least one communication bus, a user interface, a network interface, at least one memory.
[0124] The communication bus is used to realize the connection and communication between the components.
[0125] The user interface can comprise a display screen (Display) and a camera (Camera), and the optional user interface can further comprise a standard wired interface and a wireless interface.
[0126] The network interface can optionally comprise a standard wired interface and a wireless interface (such as a WI-FI interface).
[0127] The processor can include one or more processing cores. The processor connects various parts within the entire server by various interfaces and lines, executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory, and calling data stored in the memory. Optionally, the processor can be implemented in at least one of a hardware form of a digital signal processing (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor can be integrated with a combination of one or more of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content required to be displayed on the display screen; and the modem is used for processing wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor, but can be realized by a separate chip.
[0128] The memory can include a random access memory (RAM) and a read-only memory (ROM). Optionally, the memory includes a non-transitory computer-readable storage medium. The memory can be used to store instructions, programs, codes, code sets or instruction sets. The memory can include a program storage area and a data storage area, wherein the program storage area can store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area can store data involved in the above-mentioned various method embodiments, etc. The memory can also be at least one storage device located away from the above-mentioned processor. As a computer storage medium, the memory can include an operating system, a network communication module, a user interface module, and an application program of a method for improving the communication performance between H5 and Native.
[0129] In the electronic device, the user interface is mainly used to provide an input interface for the user to obtain user input data; and the processor can be used to call an application program stored in the memory for improving the communication performance between H5 and Native, which, when executed by one or more processors, causes the electronic device to perform the method of one or more of the above embodiments.
[0130] It should be noted that, for the foregoing method embodiments, the sequences of the described actions are not necessarily required to achieve the objects of the application, and certain steps can be performed in other sequences or even concurrently. Additionally, some steps can be performed concurrently or with other steps not presented. Furthermore, not all illustrated steps can be required to implement the methods described herein.
[0131] In the above embodiments, the description of each embodiment is focused on different aspects, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0132] In several embodiments provided in the present application, it should be understood that the disclosed apparatus can be implemented in other manners. For example, the described apparatus embodiments are merely schematic. For example, the division of the units is merely a logical function division. There can be another division manner for the actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections can be indirect couplings or communication connections through some interfaces, devices or units, and can be in electrical, mechanical or other forms.
[0133] The units described as separated components can or can not be physically separated, and the components displayed as units can or can not be physical units, i.e. can be located in one place or distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purposes of the embodiments of the present application.
[0134] In addition, each functional unit in the embodiments of the present application can be integrated in a processing unit, or each unit can exist physically as a separate unit, or two or more units can be integrated in one unit. The integrated unit can be implemented in the form of hardware or software function unit.
[0135] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable memory. Based on such understanding, the technical solutions of the present application essentially or say the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a memory and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the embodiments of the present application. The aforementioned memory includes: a U disk, a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0136] The above-described are only exemplary embodiments of the present disclosure, and cannot limit the scope of the present disclosure. That is, any equivalent changes and modifications made in accordance with the teachings of the present disclosure are still within the scope of the present disclosure. Other embodiments of the present disclosure will be readily apparent to those skilled in the art upon considering the disclosure. The present application is intended to cover any variations, uses or adaptive changes of the present disclosure that follow the general principles of the present disclosure and include common knowledge or conventional technical means in the technical field not recorded in the present disclosure. 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, When applied to the native side, the method includes: Obtain the first scene complexity parameter of the current H5 page. The first scene complexity parameter includes the number of nodes, script density, rendering load, interaction frequency, and network latency. Generate a scene fingerprint identification code based on the first scene complexity parameter; Match the fingerprint recognition code to a preset communication protocol according to the scenario; 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 scene complexity parameter of the current H5 page is obtained, and the preset communication protocol is re-matched according to the second scene complexity parameter.
2. The method for improving H5 and Native communication performance according to claim 1, characterized in that, The method further includes: A threshold for the first scene complexity parameter is preset. It is then determined whether the target parameter is greater than the threshold for the first scene complexity parameter. If the target parameter is greater than the threshold for the first scene complexity parameter, the rendering method of the current H5 page is reselected. The target parameter is any parameter in the first scene complexity parameter.
3. The method for improving H5 and Native communication performance according to claim 1, characterized in that, The step of generating a scene fingerprint identification code based on the first scene complexity parameter includes: The complexity parameter of the first scenario is converted into a feature vector; The feature vector is converted into a unique scene fingerprint identification code using a hash algorithm.
4. The method for improving H5 and Native communication performance according to claim 1, characterized in that, The method further includes: Create a WebView instance pool, and load the current H5 page based on the WebView instance pool; Add a reference counter to each instance in the WebView instance pool, and monitor the instances through the reference counter; When the current H5 page is detected to be destroyed, the memory occupied by the current H5 page will be released.
5. The method for improving H5 and Native communication performance according to claim 1, characterized in that, The communication with the current H5 page includes: Establish a priority queue for communication with the current H5 page, assign priorities to messages according to message type, 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 communication 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 within 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 communication with the current H5 page also includes: When a new message is received, it is compared with the target message that is currently being executed. If the new message has a higher priority than the target message, the communication of the target message is interrupted, 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 in that, It includes a parameter acquisition module, a fingerprint generation module, a protocol matching module, a communication module, and a communication monitoring module, among which: The parameter acquisition module is configured to acquire the first scene complexity parameter of the current H5 page. The first scene complexity parameter includes the number of nodes, script density, rendering load, interaction frequency, and network latency. The fingerprint generation module is configured to generate a scene fingerprint recognition code based on the first scene complexity parameter. The protocol matching module is configured to match a preset communication protocol based on the scenario 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 acquire the amount of data during communication. If the amount of data is greater than a preset threshold, the module acquires the second scene complexity parameter of the current H5 page and re-matches the preset communication protocol based on the second scene complexity parameter.
9. An electronic device, characterized in that, The device includes 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. The processor is used to execute the instructions stored in the memory to cause the electronic device to perform the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed, perform the method as described in any one of claims 1-7.
Citation Information
Patent Citations
Page parameter acquisition method, terminal equipment and medium
CN110298000A
Method for dynamically adjusting encoder parameters based on scene complexity
CN110519571A