You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By modifying the print-runtime-metrics option of the test flag to analyze memory allocations. I discovered that memory is not fully released and continue to accumulate even after the lifecycle of the objects/variables ends.
This analysis primarily compared uint64, uint256 and math/big's bigint types.
Test Methodology
Main comparison targets: uint64, uint256, math/big's bigint
Memory leaks occur when using uint256, bigint and standard library objects like strings.Builder in environment without GC or other memory management systems.
Looking at the ownership.go file, it appears that a reference counting method is applied to manage objects, but it seems to have limitations.
This can lead to performance degradation and increase gas cost, necessitating the adding appropriate memory management strategies. we might consider RAII, or GC as suggested previously.
Overview
By modifying the
print-runtime-metrics
option of thetest
flag to analyze memory allocations. I discovered that memory is not fully released and continue to accumulate even after the lifecycle of the objects/variables ends.This analysis primarily compared
uint64
,uint256
andmath/big
'sbigint
types.Test Methodology
uint64
,uint256
,math/big
'sbigint
print-runtime-metrics
flag (may differ from actual usage)Modify the
Allocator
type as follows to see how much memory is allocated for each item when the flag is used.Problem Analysis
1. Memory Leaks in Nested Scopes
uint256
,bigint
: Significant memory residue after inner scope termination2. Memory Accumulations in Loops
uint256
heap allocations are increase of 1.14kb per 10 iterations in average.Memory Usage Comparison by Type (uint: kb)
The main cause of memory leaks in loops are estimated to be as follows:
Object Creation and Absence of GC
uint256
andbigint
operations, new objects are likely to be created to store the result for each operation.Accumulation of Temporarty Objects
3. Memory Management Characteristics by Type
I also checked for similar behaviour in stdlib, such as the
strings
package, and this was also experiencing the same issue.Conclusion
Memory leaks occur when using
uint256
,bigint
and standard library objects likestrings.Builder
in environment without GC or other memory management systems.Looking at the
ownership.go
file, it appears that a reference counting method is applied to manage objects, but it seems to have limitations.This can lead to performance degradation and increase gas cost, necessitating the adding appropriate memory management strategies. we might consider RAII, or GC as suggested previously.
Related
#266
#1788
Footnotes
State after object creation only. ↩
The text was updated successfully, but these errors were encountered: