Skip to content

Conversation

@borlandong
Copy link

Related Issue

Fixes #64

Problem Description

The _lx_nand_flash_sector_read function currently reads both main data area and spare data area when matching logical sector numbers. This is unnecessary since only spare area data is needed for sector matching, resulting in severe performance degradation.

Solution

This PR optimizes the sector read logic to:

  • Read only spare area data during logical sector number matching
  • Skip main data area read when the pointer is NULL
  • Read main data area only when actually needed (after successful sector match)

Implementation Details

Modified function: _lx_nand_flash_sector_read

Key changes:

  • Separated spare area read
  • Added NULL pointer check for main data area buffer
  • Read main data area only after confirming sector match

Driver requirement:
NAND flash drivers must check if the main data area pointer is NULL and skip reading the main data area in that case.

Performance Results

Tested on W25N01GV NAND Flash with LevelX + FileX stack:

Operation Before After Improvement
Write 680KB 2258 ms 1757 ms 22.2% faster
Read 680KB 10954 ms 3113 ms 251.6% faster (3.5x)

Summary:

  • Write performance improved by ~22%
  • Read performance improved by ~252% (3.5x faster)
  • Particularly significant improvement in read operations

Testing

  • Tested on W25N01GV NAND Flash
  • Write operations verified
  • Read operations verified
  • Performance benchmarks completed

Breaking Changes

None. This is a pure performance optimization that maintains backward compatibility.

Additional Notes

This optimization is especially important for read-intensive applications. The 3.5x read performance improvement significantly enhances user experience.

@borlandong borlandong force-pushed the fix-performance-issue branch from 3a761e5 to d5e9ecf Compare January 22, 2026 03:59
@borlandong borlandong force-pushed the fix-performance-issue branch from d5e9ecf to 58dc81e Compare January 22, 2026 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance Issue: Unnecessary main data area read in _lx_nand_flash_sector_read

1 participant