Skip to content

Performance Issue: Unnecessary main data area read in _lx_nand_flash_sector_read #64

@borlandong

Description

@borlandong

Describe the bug
The function _lx_nand_flash_sector_read has a serious performance issue. The current implementation reads both the main data area and spare data area of the entire page when matching logical sector numbers, which is unnecessary and causes significant performance degradation.

Environment

  • Arm Cortex M7
  • ThreadX 6.4.1
  • arm-gnu-toolchain-13.3
  • Device: W25N01GV NAND Flash
  • Stack: LevelX + FileX
  • Test file size: 680KB

Problem Analysis
During the logical sector number matching process, we only need to read the spare area data. Reading the main data area at this stage is completely unnecessary and severely impacts performance.

Performance Impact
I implemented LevelX + FileX on W25N01GV and measured the following performance:

Before fix:

  • Write 680KB file: 2258 ms
  • Read 680KB file: 10954 ms

After fix:

  • Write 680KB file: 1757 ms
  • Read 680KB file: 3113 ms

Improvement:

  • Write performance: ~22% faster
  • Read performance: ~3.5x faster (252% improvement)

The read performance improvement is particularly significant, making this fix essential.

Proposed Solution
Optimize _lx_nand_flash_sector_read to read only the spare area during logical sector matching. The NAND flash driver should check if the main data area pointer is NULL and skip reading the main data area accordingly.

Additional context
I have already prepared a fix for this issue and will submit a PR shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    In review

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions