Skip to content

Perf: Implement lazy pool state initialization with on-demand storage #600

Description

@devdianax

Context

Pool state is fully initialized on creation regardless of whether all fields are immediately needed.

Current Limitation/Problem

Full state initialization creates storage rent burden for fields not used until later operations.

Expected Outcome

Lazy initialization pattern where pool state fields are initialized on first use rather than pool creation.

Acceptance Criteria

  • Identify deferrable state fields: not needed until first borrow, first liquidation, etc.
  • Check-exists pattern: if field not initialized, use default
  • On-first-use initialization: initialize on first operation that needs the field
  • Gas cost front-loading: defer gas cost from creation to first operation
  • Migration path for existing pools
  • Storage rent savings: initial vs lazy initialization over pool lifetime

Technical Scope

  • contracts/lending-pool/src/lazy.rs - lazy initialization pattern
  • State field classification: eager vs lazy
  • Storage rent analysis per field
  • Edge cases: concurrent first-use operations, initialization failure recovery

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions