Skip to content

[Feature]Reduce memory usage in blocks sync via delayed serialization and cache limits #6685

@xxo1shine

Description

@xxo1shine

Summary

During the block synchronization process, TRON nodes may experience cache bloat because blocks are serialized too early in the caching stage. By delaying serialization until the actual processing phase and limiting the size of the sync cache, memory usage and cache scale can be better controlled, thereby improving system stability.

Problem

Motivation

During block synchronization, nodes may need to temporarily cache a large number of block data. A more efficient memory management mechanism is required to prevent excessive resource consumption and potential impacts on node stability.

Current State

In the current implementation, blocks are serialized when they are added to the sync cache. When the number of cached blocks is large (e.g., close to 4000), the serialized data significantly increases memory usage.

Limitations or Risks

  • Early serialization leads to cache size inflation
  • High concurrency sync scenarios may cause significant memory pressure
  • Inefficient resource utilization in the block synchronization pipeline

Proposed Solution

Proposed Design

Optimize the block synchronization process as follows:

  • Delay block serialization to the actual processing stage
  • Limit the number of blocks in the sync cache to prevent unbounded growth
  • Avoid unnecessary serialization overhead and control cache size effectively

Key Changes

  • Block sync module (adjust cache management logic)
  • Block processing flow (change serialization timing)
  • Sync cache mechanism (introduce or strengthen maximum cache size limits)

Impact

  • Memory usage: Reduces memory inflation caused by early serialization
  • System stability: Lowers memory pressure in extreme sync scenarios
  • Performance: Reduces unnecessary serialization overhead during caching
  • Scalability: Improves node adaptability in large-scale synchronization scenarios

Compatibility

  • Breaking Change: No
  • Default Behavior Change: Yes (serialization is delayed)
  • Migration Required: No

This optimization does not affect external APIs or network protocols; it only impacts internal synchronization and caching logic.

Additional Notes

  • Implementation ideas: Yes
  • Willing to implement: Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions