View rendering methods, apparatus, computer equipment and storage media for streaming input
By using a syntax state machine for incremental parsing and local rendering updates under streaming input, the problem of low rendering efficiency under streaming input is solved, rendering efficiency and user experience are improved, and effective scrolling control and state feedback are provided.
Patent Information
- Application Number
- CN202611295002.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-25
- Publication Date
- 2026-11-10
AI Technical Summary
Existing technologies struggle to handle incomplete input and lack incremental parsing capabilities under streaming input, resulting in low rendering efficiency and poor user experience. In particular, they lack effective scrolling control and status feedback mechanisms during streaming output.
A pre-built grammatical state machine is used to dynamically track text data blocks, perform incremental parsing and merge local structural representations, and only locally update the layout nodes in the view. Rendering is optimized with a minimal set of modification instructions to avoid full rendering.
It enables efficient local rendering updates under streaming input, reduces computational resource consumption, improves rendering efficiency and user experience, and provides effective scrolling control and status feedback.
Smart Images

Figure CN123070053A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of deep learning inference optimization technology, and in particular to view rendering methods, apparatus, computer devices and storage media under streaming input. Background Technology
[0002] With the development of generative systems and real-time data transmission technologies, structured text such as Markdown is gradually being output in a streaming manner. Traditional methods of parsing and rendering complete text in one go are insufficient to meet the real-time and performance optimization requirements of streaming scenarios.
[0003] In the process of streaming structured text output, existing technologies typically require repeated parsing and full rendering of all received content, resulting in significant computational resource consumption and a tendency to cause interface flickering or lag. Furthermore, streaming input is incomplete; for example, code blocks and lists may be in an unclosed state. Traditional parsing methods struggle to handle such intermediate data correctly, easily leading to rendering errors or formatting issues. In addition, existing solutions lack incremental processing capabilities based on newly added content, failing to reuse existing parsing results and further reducing rendering efficiency. Regarding user experience, the lack of effective scrolling control and status feedback mechanisms during streaming output also affects the continuity of content display. Therefore, existing technologies lack a solution that supports incomplete input, possesses incremental parsing capabilities, and can perform partial rendering updates. Summary of the Invention
[0004] This application provides a view rendering method, apparatus, computer device, and storage medium under streaming input, which can solve the problem that the prior art lacks a technical solution that supports incomplete input, has incremental parsing capability, and can perform local rendering updates.
[0005] In a first aspect, embodiments of this application provide a view rendering method under streaming input, which includes:
[0006] Receive the current text data block stream arriving in sequence and append it to the input buffer, which stores the entire history from the first character to the latest character;
[0007] Based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked to obtain the nesting level of the current text data block.
[0008] Incremental parsing is performed on newly arrived text data blocks to obtain corresponding local structure representations, and the local structure representations are merged into existing structures based on the nesting level, thereby changing the structural range of the existing structures.
[0009] Based on the range of structural changes in the existing structure, only the minimum set of modification instructions is locally updated for the corresponding layout nodes in the view, without redrawing all content;
[0010] The rendering of the user view is optimized based on the minimum set of modification instructions.
[0011] In some embodiments, incremental parsing is performed on newly arrived text data blocks to obtain corresponding local structure representations, and the local structure representations are merged into existing structures based on the nesting hierarchy, including:
[0012] Incremental parsing is performed on newly arrived text data blocks to obtain corresponding lightweight syntax tree fragments;
[0013] The lightweight syntax tree fragment is attached as the last child node to the parent node of the nested hierarchy, resulting in the merged existing structure.
[0014] In some embodiments, based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked to obtain the nesting level of the current text data block, including:
[0015] If the tracking detects an unclosed structure, render the code container without a loading state or postpone the generation of the final node, and only use lightweight markers to record the boundary. When rendering the code container without a loading state, only basic styles are applied, and closure syntax highlighting is not enforced.
[0016] When subsequent data arrives, a rollback correction is triggered and completion processing is performed.
[0017] In some embodiments, based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked to obtain the nesting level of the current text data block, including:
[0018] The current full path is read from the state machine stack based on a pre-built syntactic state machine;
[0019] Based on the complete path, in the existing structure, the root node is triggered to enter the reference block node, and then the unordered list node under the reference block node is entered.
[0020] Based on the unordered list node, the text structure state of the current text block is found to obtain its nesting level.
[0021] In some embodiments, optimizing the rendering of the user view based on the minimum set of modification instructions includes:
[0022] The visible area is cropped based on the minimum set of modification instructions.
[0023] After waiting for the synchronization signal of the preset frame, submit the minimum set of modification instructions for the visible area at once;
[0024] Compensation is achieved by applying a scroll offset to the user view;
[0025] Suspend and release for invisible areas.
[0026] In some embodiments, based on the range of structural changes in the existing structure, only the minimum set of modification instructions corresponding to the corresponding layout nodes in the view is locally updated, including:
[0027] Based on the range of structural changes of the existing structure, the rendering engine maps it to the specific location in the current view layout tree;
[0028] The abstract scope of structural changes is transformed into the minimum set of modification instructions that the browser's underlying layer can execute;
[0029] The newly added complex subtree structure is constructed based on the aforementioned minimal modification instruction set;
[0030] By forcing the browser to recalculate and relay the style of the minimum set of modification instructions, the scope of the recalculation is locked within the complex subtree structure, thus obtaining the minimum set of modification instructions for local updates.
[0031] In some embodiments, based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked to obtain the nesting level of the current text data block, including:
[0032] Enumerate the states of the markup language;
[0033] Define the transition rules between the enumerated states;
[0034] Bind an action to the state transition;
[0035] Initialize context storage;
[0036] The streaming input is configured with unclosed and error recovery strategies, and the syntax state machine is constructed.
[0037] Secondly, embodiments of this application also provide a view rendering apparatus for streaming input, comprising:
[0038] A receiving unit is used to receive the current text data block stream arriving in sequence and append it to an input buffer, wherein the input buffer stores all historical content from the first character to the latest character.
[0039] The dynamic tracking unit is used to dynamically track the text structure state of the current text data block based on a pre-built syntax state machine, and to obtain the nesting level of the current text data block.
[0040] The incremental parsing unit is used to perform incremental parsing on newly arrived text data blocks to obtain the corresponding local structure representation, and to merge the local structure representation into the existing structure based on the nesting level, thereby changing the structural range of the existing structure.
[0041] The update unit is used to locally update the corresponding layout node in the view based on the structural change range of the existing structure, and without redrawing all content.
[0042] A rendering unit is used to optimize the rendering of the user view based on the minimum set of modification instructions.
[0043] Thirdly, embodiments of this application also provide a view rendering computer device under streaming input, which includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described method.
[0044] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program, the computer program including program instructions that, when executed by a processor, can implement the above-described method.
[0045] This application provides a view rendering method, apparatus, computer device, and storage medium under streaming input. The method includes: receiving sequentially arriving current text data block streams and appending them to an input buffer, the input buffer storing all historical content from the first character to the latest character; dynamically tracking the text structure state of the current text data block based on a pre-built syntax state machine to obtain the nesting level of the current text data block; incrementally parsing newly arriving text data blocks to obtain corresponding local structure representations, and merging the local structure representations into an existing structure based on the nesting level, causing a change in the structural range of the existing structure; based on the structural change range of the existing structure, locally updating only the corresponding layout nodes in the view with the minimum set of modification instructions, wherein all content is not redrawn; and optimizing the rendering of the user view based on the minimum set of modification instructions. In this application, it is not necessary to repeatedly parse and fully render all received content. Instead, it tracks text data blocks, modifies and updates only locally based on the changing structural change range, and incrementally processes newly added content separately. Rendering based on this is no longer a full parsing. This application provides a technical solution that supports incomplete input, has incremental parsing capabilities, and can perform local rendering updates. Attached Figure Description
[0046] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 A flowchart illustrating the view rendering method under streaming input provided in this application embodiment;
[0048] Figure 2 A schematic block diagram of a view rendering apparatus under streaming input provided in the embodiments of this application;
[0049] Figure 3 A schematic block diagram of a computer device provided in an embodiment of this application. Detailed Implementation
[0050] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0051] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0052] It should also be understood that the terminology used in this application specification is for the purpose of describing particular embodiments only and is not intended to limit the application. As used in this application specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0053] It should also be further understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0054] With the development of generative systems and real-time data transmission technologies, structured text such as Markdown is gradually being output in a streaming manner. Traditional methods of parsing and rendering complete text in one go are insufficient to meet the real-time and performance optimization requirements of streaming scenarios.
[0055] In the process of streaming structured text output, existing technologies typically require repeated parsing and full rendering of all received content, resulting in significant computational resource consumption and a tendency to cause interface flickering or lag. Furthermore, streaming input is incomplete; for example, code blocks and lists may be in an unclosed state. Traditional parsing methods struggle to handle such intermediate data correctly, easily leading to rendering errors or formatting issues. In addition, existing solutions lack incremental processing capabilities based on newly added content, failing to reuse existing parsing results and further reducing rendering efficiency. Regarding user experience, the lack of effective scrolling control and status feedback mechanisms during streaming output also affects the continuity of content display. Therefore, existing technologies lack a solution that supports incomplete input, possesses incremental parsing capabilities, and can perform partial rendering updates.
[0056] In some embodiments, the view rendering method under streaming input is applied to a view rendering apparatus under streaming input, which is deployed in a view rendering device under streaming input. The device is a computer device, and the view rendering computer device under streaming input can be a terminal or a server. The terminal can be a smartphone, tablet computer, PDA, or laptop computer, etc.
[0057] Figure 1 This is a flowchart illustrating the view rendering method under streaming input provided in an embodiment of this application. For example... Figure 1 As shown, the method includes the following steps S110-S150:
[0058] S110. Receive the current text data block stream that arrives in sequence and append it to the input buffer, wherein the input buffer stores all historical content from the first character to the latest character.
[0059] The system receives sequentially arriving blocks of text data and appends them to the input buffer. Streaming data is sequential and segmented. The buffer is used to smooth out peaks and valleys, preventing frequent blocking of the UI thread due to network jitter or fluctuations in generation speed. Simultaneously, the buffer retains complete historical text data, providing the raw data foundation for subsequent detection of cross-block structures.
[0060] When the system receives the Nth data block, it will not only process this new block, but will execute the following full process: text concatenation, appending the newly received data block to the complete text buffer in memory. At this time, the buffer contains all the historical content from the first character to the latest character.
[0061] S120. Based on the pre-built syntax state machine, dynamically track the text structure state of the current text data block to obtain the nesting level of the current text data block.
[0062] A complete syntax state machine must include: states, transition conditions, and actions. A state is the parser's current position and identity. It enumerates all possible structural positions, such as: currently in the root node waiting for a new block, inside a header line, inside an unclosed code block, in the third level of nesting of an ordered list, or inside inline formatting such as bold / italic. Transition conditions specify how the identity jumps when a specific character or token sequence is read. Actions are the specific operations that must be triggered when entering or exiting a state. For example, when entering a code block state, a buffer is immediately created to receive subsequent plain text; when exiting a code block state, the syntax highlighting rendering engine is immediately triggered.
[0063] A grammar state machine is a key data structure that transforms the repetitive scanning of massive amounts of historical text into real-time queries with a very small number of context variables.
[0064] Prior to S120, the steps for constructing the syntax state machine included steps A1-A5:
[0065] Step A1: Enumerate the states of the markup language;
[0066] Step A2: Define the transition rules between the enumerated states;
[0067] Step A3: Bind the action to be executed for the state transition;
[0068] Step A4: Initialize context storage;
[0069] Step A5: Configure unclosed and error recovery strategies for streaming input, and construct the syntax state machine.
[0070] The process of building a syntax state machine is essentially a systematic abstraction of the syntax rules of a specific markup language (such as Markdown) and the injection of fault-tolerant memory required for streaming processing. The entire process can be summarized into three core stages: rule definition, context handling, and exception handling, which are elaborated below:
[0071] Enumerate the states of the markup language;
[0072] First, an exhaustive classification of all possible structures for the markup language is needed to complete state enumeration. This is equivalent to creating an identity list, clearly defining the possible positions of the parser at any given time. For example, it could be waiting for a new block at the root node, inside a header line, inside a fenced code block, in an ordered or unordered list, or inside a quoted block. Simultaneously, this needs to be refined to the inline level, such as whether italics, bold, strikethrough, or links are currently being parsed. This step defines the complete working domain for the state machine, ensuring that any input character can find its corresponding context category.
[0073] The first step is to define the transition rules between the enumerated states. After determining all possible states, the second step is to define the transition rules between states, that is, to clarify which state B should be jumped to when a specific flag is encountered in state A. This is the core logical framework of the state machine. For example, in the root state, if one to six consecutive hash characters appear at the beginning of the line, it jumps to the title state; if three backticks appear at the beginning of the line, it jumps to the code block state and locks the current context; if three backticks are encountered again in the code block state, it falls back to the root state to complete the closure.
[0074] Binding actions to state transitions is crucial; however, state transitions alone are insufficient. Specific actions must be bound to each transition, defining the behavior when entering, updating, and exiting a state. This is analogous to configuring specific robotic arm actions for each intersection's turning lanes: upon entering a code block state, immediately create a new independent text buffer and record the programming language type; while in a paragraph state and continuously receiving new lines, simply append content to the end of the current paragraph without triggering new block creation; and upon exiting a list state, trigger the instruction to close the outermost list container. These hook functions translate the logical changes in state into actual manipulation of data flow and intermediate structures.
[0075] Initialize context storage; to handle the complex nested structure of Markdown, the state machine must pre-build a context storage stack. Unlike simple models that only store the current state, this stack completely records the entire path from the root node to the current position. For example, when the parser is at the deepest list item, the stack may sequentially store the root state, the reference block state, the list state, and the list item state. In addition, the stack also needs to maintain an indentation counter and an unclosed marker queue to accurately determine whether the next line of added content is to continue the current child item or to start a new sibling node.
[0076] Configure unclosed and error recovery strategies for streaming input and construct the syntax state machine.
[0077] Finally, to address the inherent data incompleteness of streaming input, pre-configured unclosed block and error recovery strategies are necessary—a unique step absent in traditional offline parsers. It must be explicitly stipulated that if the top of the stack remains an unclosed code block during a stream interruption or pause, the rendering end should forcibly demoted it to a plain text placeholder and cease syntax highlighting attempts. If inline formatting markers are detected, with only a left side and no right side, these markers should be actively ignored, degenerating into plain text to prevent subsequent content from becoming corrupted. For unclosed headings, single-line content should be treated as a completed block and forcibly closed. These fallback rules ensure that regardless of where the data stream abruptly ends, the user interface will not display widespread parsing errors or syntax collapses.
[0078] Once all four rules are defined, the system obtains a state machine template that can be repeatedly instantiated at startup. Subsequently, whenever a streaming data block arrives, the engine uses these pre-defined rules, combined with the real-time memory stored in the stack, to perform table lookups and action callbacks for newly added characters, thus systematically organizing the seemingly chaotic input stream into a well-structured hierarchy.
[0079] S120 includes S1201-S1202:
[0080] S1201. Perform incremental parsing on the newly arrived text data block to obtain the corresponding lightweight syntax tree fragment;
[0081] Merging anchors should be found based on nesting levels because streaming may involve multiple levels of nesting, such as reference blocks > lists > list items. Merging based solely on type might incorrectly insert new list items into other parallel lists.
[0082] Read the current complete path from the state machine stack, for example, [ROOT, BLOCKQUOTE, UL_LIST]. Use this path to traverse the existing structure tree: starting from the root node, enter the reference block node, and then enter the unordered list node under that reference block. Locate the target parent node, that is, the specific memory address of this UL_LIST node.
[0083] S1202. The lightweight syntax tree fragment is attached as the last child node to the parent node of the nested level to obtain the merged existing structure.
[0084] When a new block of text data enters the buffer, the state machine does not immediately match it with historical content. Instead, it first performs a very lightweight pre-scan of the data block, counting the number of spaces / indentation at the beginning of each line and detecting special markers at the beginning of each line. This is to determine whether the line is the start of a completely new structure or a continuation of the previous structure.
[0085] The state machine retrieves the starting coordinates from the current context stack. Before applying any new rules, the state machine must first determine its current position. It immediately reads the pre-maintained context stack. The current resolution position is inside the reference block under the root node, and one level inward, it's inside an unordered list. The top of this stack is the logical starting point of this operation. The transition function is executed, and the state stack is updated. The state machine combines the scanned markers with the retrieved current top stack state for joint judgment. Based on the judgment result, different stack operations are performed: If the scan finds a sibling list item, no new type is pushed; it remains at the top of the stack, only its index position is recorded, and the stack remains unchanged. If the scan finds a line with 4 spaces at the beginning of its indentation, and the current top stack is UL_LIST, rule judgment: this content belongs to the current list item's internal paragraph or sub-code block. The new sub-state PARAGRAPH or INDENT_CODE is pushed onto the top of the stack. The stack becomes [ROOT, BLOCKQUOTE, UL_LIST, PARAGRAPH].
[0086] The entire process only involves pushing and popping elements from the top of the stack, never backtracking to scan historical nodes below the stack. The instant the stack update is complete, the state machine immediately calculates the current physical depth of the stack. This instantaneously calculated number is used to quickly locate the parent container's path coordinates in the global syntax tree during subsequent local structure merging.
[0087] In addition to the push and pop operations of the block-level structure, the state machine also maintains a set of lightweight unclosed flags within the line while tracking the hierarchy. When subsequent data blocks arrive, even if they are at different block nesting levels, the state machine will still force a query for this active flag to ensure that the characters in the new block are rendered with the correct inline style, until a closure character is received in the future to clear the flag.
[0088] Following S120, steps B1-B2 are included:
[0089] Step B1: If the tracking detects the existence of an unclosed structure, render the code container without loading state or postpone the generation of the final node, and only use lightweight markers to record the boundary. When rendering the code container without loading state, only the basic style is given, and the closing syntax highlighting is not forced.
[0090] Step B2: When subsequent data arrives, trigger rollback correction and perform completion processing.
[0091] For detected unclosed structures, a placeholder or delayed parsing strategy is adopted, and completion processing is performed when subsequent data arrives. For detected unclosed structures such as unclosed code or unclosed bold **, a placeholder or delayed parsing strategy is adopted, and completion and correction are performed when subsequent data arrives.
[0092] In some embodiments, a placeholder strategy may also be adopted. For example, if the code block is detected to have started but not ended, it is first rendered as a loaded code container, and only basic styles are given without mandatory closing syntax highlighting.
[0093] The deferred parsing strategy refers to delaying the generation of the final DOM nodes for complex lists or tables, and only using lightweight markers to record boundaries.
[0094] The completion-time correction mechanism triggers a rollback correction when subsequent data arrives and closes the structure. This includes instantiating the previous placeholder container into a full code block and triggering highlight rendering. This mechanism ensures that even when data is incomplete, the interface will not experience widespread formatting corruption.
[0095] S130. Incrementally parse the newly arrived text data block to obtain the corresponding local structure representation, and merge the local structure representation into the existing structure based on the nesting level, so that the structural range corresponding to the existing structure changes.
[0096] S130 includes S1301-S1302:
[0097] S1301. Perform incremental parsing on the newly arrived text data block to obtain the corresponding lightweight syntax tree fragment;
[0098] S1302. The lightweight syntax tree fragment is attached as the last child node to the parent node of the nested level to obtain the merged existing structure.
[0099] After finding the parent node, the actual tree operations are performed. This step does not simply replace the old node with the new one, but rather employs two different grafting strategies based on structural integrity:
[0100] Scenario A: Normal addition
[0101] If the new text data block is a completely closed list item, the generated node is attached to the locked parent node as the last child node. Existing nodes remain unchanged, and their pointer addresses are not modified.
[0102] Scenario B: Placeholder Correction
[0103] If a placeholder container already existed in the existing structure due to incomplete data closure, and the new data block now provides a closure and parses out the complete code content, instead of deleting the old placeholder and adding a new one, the memory address of the old placeholder is reused, its type is changed from "placeholder" to "code_block," and the content is injected. This in-place upgrade minimizes the risk of invalid child node references.
[0104] S140. Based on the structural change range of the existing structure, only locally update the corresponding minimum set of modification instructions for the corresponding layout nodes in the view, wherein all content is not redrawn.
[0105] S140 includes S1401-S1404:
[0106] S1401. Based on the structural change range of the existing mechanism, map it to the specific location of the current view layout tree through the rendering engine;
[0107] The change region mapping is from logical coordinates to physical coordinates, receiving structural change patches from the incremental resolver. The rendering engine immediately maps it to its specific location in the current view layout tree. The anchor parent container of this logical node on the screen is determined.
[0108] S1402. Transform the abstracted range of structural changes into the minimum set of modification instructions that the browser's underlying layer can execute;
[0109] Translate abstract structural changes into the smallest atomic instructions that the browser can execute at the underlying level. This typically involves only four types of operations: Insert, creating a new node at the Nth position of a specified parent container; Remove, deleting a specific old node, such as when an unclosed placeholder is replaced; Move, adjusting the order of nodes; and Replace, replacing the text content or attributes of nodes, such as replacing "placeholder container" with "highlighted code block".
[0110] This stage merges similar commands from adjacent areas. For example, inserting five consecutive text blocks is merged into one batch insert command, reducing the number of subsequent interactions with the browser.
[0111] S1403. Construct the newly added complex subtree structure based on the minimum modification instruction set;
[0112] Isolation DOM tree mutation utilizes the atomic instructions generated in the previous step to directly manipulate the DOM tree in the browser's memory. However, it never touches the unchanged parent container.
[0113] The newly added complex subtree structure is built offline in memory using document fragments, and then mounted to the parent node all at once. For changes to text nodes, `node.textContent = 'new value'` is called directly, without destroying or rebuilding the node. This step marks the smallest dirty area in the browser's rendering engine that needs to recalculate styles.
[0114] S1404. By forcing the browser to recalculate and relay the style of the minimum modification instruction set, the recalculation scope is locked within the complex subtree structure, thus obtaining the minimum modification instruction set for local updates.
[0115] Limiting the scope of style and geometry recalculation forces the browser to recalculate and relay styles, but by utilizing layout boundary characteristics, the recalculation scope is strictly locked within the modified subtree.
[0116] For newly added nodes, only the size and position of the node itself and its descendant nodes are calculated. For its parent container, since the total size may change, only its scrollHeight and bounding rect are updated, but any geometric properties of sibling nodes above the parent container are no longer recursively calculated. The process that originally required traversing 100,000 nodes to calculate their positions now only requires calculating the boundary values of the newly added node and the parent container.
[0117] After DOM changes and layout calculations are complete, immediately read the user's current interaction state and perform view-based synchronization: determine the follow mode by obtaining the distance between the bottom of the current scrollbar and the bottom of the content. If the difference is less than a preset threshold, determine that the user is in follow mode. Perform scroll compensation; if in follow mode, call the smooth scrolling interface to move the latest rendered node to the bottom of the viewport; if the user is manually reviewing history, lock the scroll position and never seize control. Update visual feedback, notifying the user in phase five to update the position of the dynamic indicator at the end.
[0118] After the entire process is completed, the rendering engine will perform a very lightweight check, comparing the expected rendering result calculated by this patch with the actual pixel boundaries drawn on the screen. If the offset is caused by cross-domain font loading or sudden changes in image size, a fine-tuning compensation will be triggered immediately, but the retry will only be performed on the new node and will never involve a full redraw.
[0119] S150. Optimize the rendering of the user view based on the minimum set of modification instructions.
[0120] S150 includes S1501-S1504:
[0121] S1501. The visible area is cropped based on the minimum set of modification instructions.
[0122] S1502. After waiting for the synchronization signal of the preset frame, submit the minimum set of modification instructions for the visible area at once;
[0123] S1503. Compensation is achieved by applying a scroll offset to the user view;
[0124] S1504, Suspend and release for invisible areas.
[0125] Determine if the user is manually reviewing historical content based on their view position. If the user is at the bottom and new content is added, automatically scroll to the latest content area. Add a dynamic indicator at the end of the streaming output, such as a blinking cursor or a wavy line indicating "Inputting...".
[0126] If a user forcibly scrolls to the bottom while reading the history content above, it will disrupt the reading experience. The solution monitors the difference between the scroll offset and the maximum scroll distance, and sets a threshold. If the difference is less than 50 pixels, it is considered to be in follow mode, and automatic scrolling is only enabled in follow mode.
[0127] Utilizing the principle of visual continuity, the presence of markers clearly communicates to the user that the system is generating data, without lag, effectively reducing user anxiety while waiting, and providing a clear visual transition to the final rendering completion state.
[0128] Once the new text data block arrives and completes incremental parsing and merging, the rendering optimization engine executes decisions in the following order: First, it calculates the range of changes between the old and new tree structures by comparing differences, and then generates the minimum instruction set corresponding to the current change, i.e., the patch set. Before performing any operations that might change the page height, it immediately freezes and records the anchor element at the top of the current user viewport and its offset relative to the viewport. This is to prevent subsequent operations from causing page jumps.
[0129] The visible area of the patch set is then determined. If the node affected by the patch is outside the current visible area of the screen, it is suspended, and only the data structure in memory is updated; the actual DOM is not manipulated yet. If the patch is within the visible area, it is sent to the batch queue to be executed. The engine waits for the browser's next vertical synchronization signal, which is the next screen refresh frame approximately 16.7 milliseconds later. When this signal arrives, all visible area patches accumulated in the batch queue are submitted to the DOM tree at once.
[0130] After the batch DOM changes are completed, the page height may have changed. At this point, the engine uses the frozen anchor point data to calculate the distance the height has expanded and performs precise scroll compensation to ensure that the user's eye anchor point remains stationary.
[0131] Finally, in the background, during idle time, the suspended patches located outside the viewport are asynchronously updated one by one to maintain consistency between the memory model and the final DOM.
[0132] This application provides a view rendering method, apparatus, computer device, and storage medium under streaming input. The method includes: receiving a sequentially arriving stream of current text data blocks and appending it to an input buffer, the input buffer storing all historical content from the first character to the latest character; dynamically tracking the text structure state of the current text data block based on a pre-built syntax state machine to obtain the nesting level of the current text data block; incrementally parsing newly arriving text data blocks to obtain corresponding local structure representations, and merging the local structure representations into an existing structure based on the nesting level, where the structural range of the existing structure changes; based on the structural change range of the existing structure, locally updating only the corresponding layout nodes in the view with the minimum set of modification instructions, wherein all content is not redrawn; and optimizing the rendering of the user view based on the minimum set of modification instructions. In this application, it is not necessary to repeatedly parse and fully render all received content. Instead, it tracks text data blocks, modifies and updates only locally based on the changing structural change range, and incrementally processes newly added content separately. Rendering based on this is no longer a full parsing. This application provides a technical solution that supports incomplete input, has incremental parsing capabilities, and can perform local rendering updates.
[0133] Figure 2 This is a schematic block diagram of a view rendering device under streaming input provided in an embodiment of this application. Figure 2 As shown, corresponding to the above-described view rendering method under streaming input, this application also provides a view rendering apparatus 600 under streaming input. This view rendering apparatus 600 under streaming input includes a unit for executing the above-described view rendering method under streaming input, and can be configured in terminals such as desktop computers, tablet computers, and laptops. Specifically, please refer to... Figure 2 The view rendering apparatus 600 under streaming input includes a receiving unit 601, a dynamic tracking unit 602, an incremental parsing unit 603, an update unit 604, and a rendering unit 605, wherein:
[0134] The receiving unit 601 is used to receive the current text data block stream that arrives in sequence and append it to the input buffer, wherein the input buffer stores all historical content from the first character to the latest character;
[0135] The dynamic tracking unit 602 is used to dynamically track the text structure state of the current text data block based on a pre-built syntax state machine, so as to obtain the nesting level of the current text data block.
[0136] The incremental parsing unit 603 is used to perform incremental parsing on newly arrived text data blocks to obtain the corresponding local structure representation, and to merge the local structure representation into the existing structure based on the nesting level, thereby changing the structural range corresponding to the existing structure.
[0137] The update unit 604 is used to update the minimum set of modification instructions for the corresponding layout nodes in the view only based on the range of structural changes of the existing structure, wherein all content is not redrawn.
[0138] Rendering unit 605 is used to optimize the rendering of the user view based on the minimum set of modification instructions.
[0139] In some embodiments, the incremental parsing unit 603 performs incremental parsing on newly arrived text data blocks to obtain corresponding local structure representations, and merges the local structure representations into existing structures based on the nesting hierarchy, specifically for:
[0140] Incremental parsing is performed on newly arrived text data blocks to obtain corresponding lightweight syntax tree fragments;
[0141] The lightweight syntax tree fragment is attached as the last child node to the parent node of the nested hierarchy, resulting in the merged existing structure.
[0142] In some embodiments, the view rendering device 600 under streaming input further includes a completion unit, which dynamically tracks the text structure state of the current text data block based on a pre-built syntax state machine. After obtaining the nesting level of the current text data block, the completion unit is specifically used for:
[0143] If the tracking detects an unclosed structure, render the code container without a loading state or postpone the generation of the final node, and only use lightweight markers to record the boundary. When rendering the code container without a loading state, only basic styles are applied, and closure syntax highlighting is not enforced.
[0144] When subsequent data arrives, a rollback correction is triggered and completion processing is performed.
[0145] In some embodiments, the completion unit dynamically tracks the text structure state of the current text data block based on a pre-built syntax state machine to obtain the nesting level of the current text data block, specifically for:
[0146] The current full path is read from the state machine stack based on a pre-built syntactic state machine;
[0147] Based on the complete path, in the existing structure, the root node is triggered to enter the reference block node, and then the unordered list node under the reference block node is entered.
[0148] Based on the unordered list node, the text structure state of the current text block is found to obtain its nesting level.
[0149] In some embodiments, the rendering unit 605 performs rendering optimization of the user view based on the minimum set of modification instructions, specifically for:
[0150] The visible area is cropped based on the minimum set of modification instructions.
[0151] After waiting for the synchronization signal of the preset frame, submit the minimum set of modification instructions for the visible area at once;
[0152] Compensation is achieved by applying a scroll offset to the user view;
[0153] Suspend and release for invisible areas.
[0154] In some embodiments, the update unit 604, when executing the minimum set of modification instructions based on the structural change range of the existing structure, only locally updates the corresponding layout nodes in the view, specifically for:
[0155] Based on the range of structural changes of the existing structure, the rendering engine maps it to the specific location in the current view layout tree;
[0156] The abstract scope of structural changes is transformed into the minimum set of modification instructions that the browser's underlying layer can execute;
[0157] The newly added complex subtree structure is constructed based on the aforementioned minimal modification instruction set;
[0158] By forcing the browser to recalculate and relay the style of the minimum set of modification instructions, the scope of the recalculation is locked within the complex subtree structure, thus obtaining the minimum set of modification instructions for local updates.
[0159] In some embodiments, the view rendering device 600 under streaming input further includes a syntax state machine construction unit. Before dynamically tracking the text structure state of the current text data block based on a pre-built syntax state machine to obtain the nesting level of the current text data block, the syntax state machine construction unit is specifically used for:
[0160] Enumerate the states of the markup language;
[0161] Define the transition rules between the enumerated states;
[0162] Bind an action to the state transition;
[0163] Initialize context storage;
[0164] The streaming input is configured with unclosed and error recovery strategies, and the syntax state machine is constructed.
[0165] In summary, the view rendering device 600 under streaming input in this embodiment receives the current text data block stream arriving sequentially and appends it to the input buffer, which stores all historical content from the first character to the latest character. Based on a pre-built syntax state machine, it dynamically tracks the text structure state of the current text data block to obtain the nesting level of the current text data block. It incrementally parses newly arriving text data blocks to obtain the corresponding local structure representation, and merges the local structure representation into the existing structure based on the nesting level, causing a change in the structural range of the existing structure. Based on the structural change range of the existing structure, it only locally updates the corresponding layout nodes in the view with the minimum set of modification instructions, without redrawing all content. It then optimizes the rendering of the user view based on the minimum set of modification instructions. In this application, it is not necessary to repeatedly parse and fully render all received content. Instead, it tracks text data blocks, modifies and updates only locally based on the changing structural change range, and incrementally processes newly added content. Rendering based on this is no longer a full parsing. This application provides a technical solution that supports incomplete input, has incremental parsing capabilities, and can perform local rendering updates.
[0166] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the view rendering device and each unit under the above-mentioned streaming input can be referred to the corresponding description in the foregoing method embodiments. For the sake of convenience and brevity, it will not be repeated here.
[0167] The aforementioned view rendering device under streaming input can be implemented as a computer program, which can, for example... Figure 3 It runs on the computer device shown.
[0168] Please see Figure 3 , Figure 3 This is a schematic block diagram of a computer device 700 provided in an embodiment of this application. The computer device 700 can be a terminal or a server. The terminal can be an electronic device with communication functions, such as a smartphone, tablet, laptop, desktop computer, personal digital assistant, or wearable device. The server can be a standalone server or a server cluster composed of multiple servers.
[0169] See Figure 3 The computer device 700 includes a processor 702, a memory, and a network interface 705 connected via a system bus 701. The memory may include a non-volatile storage medium 703 and internal memory 704.
[0170] The non-volatile storage medium 703 may store an operating system 7031 and a computer program 7032. The computer program 7032 includes program instructions that, when executed, cause the processor 702 to perform a view rendering method under streaming input.
[0171] The processor 702 provides computing and control capabilities to support the operation of the entire computer device 700.
[0172] The internal memory 704 provides an environment for the execution of the computer program 7032 in the non-volatile storage medium 703. When the computer program 7032 is executed by the processor 702, the processor 702 can execute a view rendering method under streaming input.
[0173] This network interface 705 is used for network communication with other devices. Those skilled in the art will understand that... Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 700 to which the present application is applied. The specific computer device 700 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0174] The processor 702 is used to run the computer program 7032 stored in the memory to perform the following steps:
[0175] Receive the current text data block stream arriving in sequence and append it to the input buffer, which stores the entire history from the first character to the latest character;
[0176] Based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked to obtain the nesting level of the current text data block.
[0177] Incremental parsing is performed on newly arrived text data blocks to obtain corresponding local structure representations, and the local structure representations are merged into existing structures based on the nesting level, thereby changing the structural range of the existing structures.
[0178] Based on the range of structural changes in the existing structure, only the minimum set of modification instructions is locally updated for the corresponding layout nodes in the view, without redrawing all content;
[0179] The rendering of the user view is optimized based on the minimum set of modification instructions.
[0180] It should be understood that in the embodiments of this application, the processor 702 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0181] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.
[0182] It should be noted that the specific embodiments are merely illustrative examples intended to aid in understanding the technical solutions of the present invention, and are not intended to limit the scope of protection of the present invention. The scope of protection of this application is determined by the contents of the claims. Specific embodiments, parameter ranges, or technical features described in the specification should not be construed as undue limitation or expansion of the scope of protection of the claims. The technical effects described in the specification are only used to illustrate the innovation of the present invention. Any technical solution that does not simultaneously possess all the technical features of the present invention, even if it claims to solve the same technical problem, does not fall within the scope of protection of the present invention.
[0183] Therefore, this application also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions. When executed by a processor, the program instructions cause the processor to perform the following steps:
[0184] Receive the current text data block stream arriving in sequence and append it to the input buffer, which stores the entire history from the first character to the latest character;
[0185] Based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked to obtain the nesting level of the current text data block.
[0186] Incremental parsing is performed on newly arrived text data blocks to obtain corresponding local structure representations, and the local structure representations are merged into existing structures based on the nesting level, thereby changing the structural range of the existing structures.
[0187] Based on the range of structural changes in the existing structure, only the minimum set of modification instructions is locally updated for the corresponding layout nodes in the view, without redrawing all content;
[0188] The rendering of the user view is optimized based on the minimum set of modification instructions.
[0189] The storage medium can be any computer-readable storage medium that can store program code, such as a USB flash drive, external hard drive, read-only memory (ROM), magnetic disk, or optical disk.
[0190] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this application.
[0191] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0192] The steps in the methods of this application embodiment can be adjusted, merged, or deleted according to actual needs. The units in the apparatus of this application embodiment can be merged, divided, or deleted according to actual needs. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0193] 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 storage medium. Based on this understanding, the technical solution of this application, in essence, or the part 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 storage medium and includes several instructions to cause a computer device (which may be a personal computer, terminal, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application.
[0194] It should be noted that any software tools or components not belonging to this company appearing in the embodiments of this application are merely illustrative examples and do not represent actual use. All user personal information involved in the embodiments of this application is authorized (with the knowledge and consent) by the relevant parties or fully authorized by all parties, and the executing entity may obtain it through various legal and compliant means. The collection, storage, use, processing, transmission, provision, and disclosure of the information, data, and signals involved all comply with relevant laws and regulations and do not violate public order and good morals.
[0195] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A view rendering method under streaming input, characterized in that, The method includes: Receive the current text data block stream arriving in sequence and append it to the input buffer, which stores the entire history from the first character to the latest character; Based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked to obtain the nesting level of the current text data block. Incremental parsing is performed on newly arrived text data blocks to obtain corresponding local structure representations, and the local structure representations are merged into existing structures based on the nesting level, thereby changing the structural range of the existing structures. Based on the range of structural changes in the existing structure, only the minimum set of modification instructions is locally updated for the corresponding layout nodes in the view, without redrawing all content; The rendering of the user view is optimized based on the minimum set of modification instructions.
2. The method according to claim 1, characterized in that, Incremental parsing is performed on newly arrived text data blocks to obtain corresponding local structure representations, and these local structure representations are merged into existing structures based on the nesting hierarchy, including: Incremental parsing is performed on newly arrived text data blocks to obtain corresponding lightweight syntax tree fragments; The lightweight syntax tree fragment is attached as the last child node to the parent node of the nested hierarchy, resulting in the merged existing structure.
3. The method according to claim 1, characterized in that, Based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked. After obtaining the nesting level of the current text data block, the following is included: If the tracking detects an unclosed structure, render the code container without a loading state or postpone the generation of the final node, and only use lightweight markers to record the boundary. When rendering the code container without a loading state, only basic styles are applied, and closure syntax highlighting is not enforced. When subsequent data arrives, a rollback correction is triggered and completion processing is performed.
4. The method according to claim 1, characterized in that, Based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked to obtain the nesting level of the current text data block, including: The current full path is read from the state machine stack based on a pre-built syntactic state machine; Based on the complete path, in the existing structure, the root node is triggered to enter the reference block node, and then the unordered list node under the reference block node is entered. Based on the unordered list node, the text structure state of the current text block is found to obtain its nesting level.
5. The method according to claim 1, characterized in that, Optimize the rendering of the user view based on the minimum set of modification instructions, including: The visible area is cropped based on the minimum set of modification instructions. After waiting for the synchronization signal of the preset frame, submit the minimum set of modification instructions for the visible area at once; Compensation is achieved by applying a scroll offset to the user view; Suspend and release for invisible areas.
6. The method according to claim 1, characterized in that, Based on the structural change range of the existing structure, only the minimum set of modification instructions corresponding to the local update of the corresponding layout nodes in the view is applied, including: Based on the range of structural changes of the existing structure, the rendering engine maps it to the specific location in the current view layout tree; The abstract scope of structural changes is transformed into the minimum set of modification instructions that the browser's underlying layer can execute; The newly added complex subtree structure is constructed based on the aforementioned minimal modification instruction set; By forcing the browser to recalculate and relay the style of the minimum set of modification instructions, the scope of the recalculation is locked within the complex subtree structure, thus obtaining the minimum set of modification instructions for local updates.
7. The method according to claim 1, characterized in that, Based on a pre-built grammatical state machine, the text structure state of the current text data block is dynamically tracked to obtain the nesting level of the current text data block, including: Enumerate the states of the markup language; Define the transition rules between the enumerated states; Bind an action to the state transition; Initialize context storage; The streaming input is configured with unclosed and error recovery strategies, and the syntax state machine is constructed.
8. A view rendering device under streaming input, characterized in that, The device includes: A receiving unit is used to receive the current text data block stream arriving in sequence and append it to an input buffer, wherein the input buffer stores all historical content from the first character to the latest character. The dynamic tracking unit is used to dynamically track the text structure state of the current text data block based on a pre-built syntax state machine, and to obtain the nesting level of the current text data block. The incremental parsing unit is used to perform incremental parsing on newly arrived text data blocks to obtain the corresponding local structure representation, and to merge the local structure representation into the existing structure based on the nesting level, thereby changing the structural range of the existing structure. The update unit is used to locally update the corresponding layout node in the view based on the structural change range of the existing structure, and without redrawing all content. A rendering unit is used to optimize the rendering of the user view based on the minimum set of modification instructions.
9. A view rendering computer device for streaming input, characterized in that, The method includes a memory, a processor, and a view rendering program for streaming input stored on the memory and executable on the processor, wherein the processor executes the view rendering program for streaming input to implement the steps of the view rendering method for streaming input according to any one of claims 1 to 7.
10. A storage medium, characterized in that, The medium stores a program that implements a view rendering method under streaming input, the program being executed by a processor to implement the steps of the view rendering method under streaming input as claimed in any one of claims 1 to 7.
