Dynamic Array Representation Conversion for Runtime Type Optimization
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Dynamically-typed languages face challenges in efficiently representing and manipulating double-precision floating-point values due to unknown types at runtime, leading to suboptimal memory usage and performance when using 'raw' storage formats.
Innovation Solution
The method involves tracking the representation format and packing status of arrays in dynamically-typed programming languages, allowing for conversion between different formats (small integer, double value, or tagged) based on element types and operations, thereby optimizing memory usage and performance by auto-unboxing double arrays.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Quantity of substance
If dynamically-typed languages use raw storage format for double values, then memory usage is reduced, but performance deteriorates due to unknown types at runtime
Solution Approach 1:
The patent implements dynamic type representation where the storage format of array elements is not fixed but adapts at runtime based on the actual element types. The system tracks element kinds (small integer, double value, or tagged) and converts storage formats dynamically, allowing the same array structure to optimize for both memory efficiency and performance based on runtime type information.
Solution Approach 2:
The patent changes the representation parameter of array elements from a static format to a dynamic format that can switch between different representations (boxed vs unboxed, different element kinds). This parameter change allows the system to select the most efficient storage format based on runtime type analysis, resolving the contradiction between memory efficiency and performance.
2Reliability
If dynamically-typed languages use boxed representation for all values, then type safety is maintained, but memory consumption increases
Solution Approach 1:
The patent applies different storage representations to different parts of the array based on local type characteristics. Instead of uniformly boxing all values, the system identifies regions with homogeneous element kinds and applies specialized unboxed representations (small integer, double value) to those specific regions while maintaining boxed representation only where necessary for type safety.
Solution Approach 2:
The patent segments the array into different element kind regions (small integer elements, double value elements, tagged elements) and applies different storage formats to each segment. This segmentation allows the system to maintain type safety through proper representation tracking while reducing overall memory consumption by using efficient unboxed formats for homogeneous segments.
3Productivity
If the compiler generates efficient code for raw storage, then performance is improved, but adaptability to different types at runtime is reduced
Solution Approach 1:
The patent makes the code generation process dynamic by incorporating runtime type information into compilation decisions. The compiler generates code that can adapt its storage format and access patterns based on the actual element kinds discovered at runtime, allowing efficient unboxed code generation for specific types while maintaining the ability to handle type variations through dynamic conversion mechanisms.
Data Source
Figure 1
Figure 2
Figure 3
AI summary
Representation of an array in dynamically-typed program code at runtime is provided. Program code is accessed at runtime. An instruction for adding, updating or deleting one or more elements for an array is detected within the code. The array is associated with a first kind of element comprising a first representation and packing format. A second kind of element is determined based on at least one of the instruction or the one or more elements, the second kind of element comprising at least one of a second representation or packing format. A determination is made that the first and second kind of elements are not consistent, based on an inconsistency between the first and second representation formats or packing formats. The array is converted so that the first and second kind of elements are consistent. One or more array elements are added, updated or deleted based on the instruction.