Skip to content

refactor(FileDataBuffer): O(1) LRU cache, fix hash mismatch, deduplicate save logic#151

Open
lagcompensation wants to merge 6 commits into
munirov:mainfrom
lagcompensation:main
Open

refactor(FileDataBuffer): O(1) LRU cache, fix hash mismatch, deduplicate save logic#151
lagcompensation wants to merge 6 commits into
munirov:mainfrom
lagcompensation:main

Conversation

@lagcompensation

@lagcompensation lagcompensation commented Apr 7, 2026

Copy link
Copy Markdown
  • Replace QList-based LRU with std::list + QHash for O(1) chunk touch/evict
  • Add touchChunkLocked / trimChunkCacheLocked implementations
  • Unify computeCurrentHashLocked to use qHash in both modes (fixes isModified()
    returning wrong result after file-backed → memory transition)
  • Extract reopenSource lambda in saveToFile to remove triplicated recovery blocks
  • Skip O(n) data comparison in replaceData if sizes differ
  • Fix stale m_chunkLru.clear() reference in openFile → use m_chunkLruList/Iter

@igmunv igmunv requested a review from Altro-O April 8, 2026 04:40

@Altro-O Altro-O left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileDataBuffer.cpp:76-80, 422-434
The reported fix for hash mismatch is not complete. After replaceData(), the file-backed buffer is still forced to memory mode via promoteToMemoryModeLocked(), and computeCurrentHashLocked() still calculates the hash differently in the two modes: qHash(m_data, 0) for materialized and XOR from qHash(readLocked(...), offset) for file-backed. As a result, isModified() can still be true without actually changing the data, if the contents haven't changed, but only the storage mode has.

FileDataBuffer.h:4-10, 107-108
std::list and std::list<...>::iterator have appeared in the header, but #include has not been added. This can currently only be built accidentally due to transitive includes, but any TU that includes this header without them will get a compile error.

Please correct the errors and we will review them again.

@lagcompensation

Copy link
Copy Markdown
Author

@Altro-O fixed

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.

2 participants