JavaScript Multi-Thread Refactoring via DOM Segmentation
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Multi-threading in software development, particularly for dynamic languages like JavaScript, poses challenges due to thread interactions, conflicts, and blocking issues, which complicates the execution and development of software applications on multi-core processing devices.
Innovation Solution
The method involves refactoring JavaScript code for multi-threading by creating background processes, analyzing code entries to create dependency records, and separating interacting code entries from document object modules (DOM) interactions, allowing for concurrent execution without blocking the main execution path.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of operation
If JavaScript code is executed in a single thread, then the execution path is simple and easy to control, but the main execution path is blocked when background operations are performed
Solution Approach 1:
The patent segments the JavaScript code execution into two independent parts: a main execution path that handles user interface operations and a background execution path that handles computational tasks. This segmentation is achieved by creating separate execution contexts with independent stacks, allowing the main path to remain simple while background operations execute concurrently without blocking.
Solution Approach 2:
The patent introduces a new dimension of execution by implementing background execution paths that operate independently from the main execution path. This dimensional separation allows background operations to execute in parallel without interfering with the main UI thread, effectively transforming single-threaded sequential execution into multi-dimensional concurrent execution.
2Productivity
If multi-threading is implemented in JavaScript, then concurrent execution and productivity are improved, but thread interactions and conflicts increase complexity
Solution Approach 1:
The patent extracts the complexity of thread interaction management from the main execution path by implementing a dedicated background execution mechanism. The background path isolates potential conflicts and interactions within its own execution context, preventing them from propagating to the main thread. This extraction allows concurrent execution to proceed without exposing the main codebase to complex synchronization issues.
Solution Approach 2:
The patent introduces an intermediary execution context structure that mediates between the main execution path and background operations. This intermediary layer handles the coordination and communication between threads, absorbing the complexity of thread interactions while presenting a simple interface to the main execution path. The intermediary manages resource sharing and synchronization without requiring explicit conflict resolution code in the main application.
3Device complexity
If background code entries are executed without separation from DOM interactions, then code structure remains simple, but blocking and conflicts with main execution path occur
Solution Approach 1:
The patent segments code entries into two distinct groups: those that interact with the DOM and those that perform background computations. By separating DOM-interacting code from background code, the patent eliminates blocking issues while maintaining relatively simple code structures. Each segment has clearly defined responsibilities and execution contexts, making the overall system more reliable without requiring complex refactoring.
Data Source
AI summary
Computer implemented method of refactoring JavaScript code for multi-threading concurrent execution, comprising:1) Designating a source code which includes background code entries indicated by a user as executed in background.2) Analyzing the source code entries to create a dependency record.3) Creating a background process comprising the background code entries and removing code entries which read or write from DOM(s).4) Creating a handler code comprising the write code entries.5) Creating main code which includes:(a) Remaining code entries not included in the background process and the handler code.(b) Process initiation code initiating the background process. The process initiation code is placed at a process initiation point identified based on the dependency record which follows the read code entries in the source code execution path and precedes the write code entries.6) Outputting refactored code file(s) which include the background process, handler code and main code.


