refactor: Memory optimization and XTC format removal

Memory optimization:
- Add LOG_STACK_WATERMARK macro for task stack monitoring
- Add freeCoverBufferIfAllocated() and preloadCoverBuffer() for memory management
- Improve cover buffer reuse to reduce heap fragmentation
- Add grayscale buffer cleanup safety in GfxRenderer
- Make grayscale rendering conditional on successful buffer allocation
- Add detailed heap fragmentation logging with ESP-IDF API
- Add CSS parser memory usage estimation

XTC format removal:
- Remove entire lib/Xtc library (XTC parser and types)
- Remove XtcReaderActivity and XtcReaderChapterSelectionActivity
- Remove XTC file handling from HomeActivity, SleepActivity, ReaderActivity
- Remove .xtc/.xtch from supported extensions in BookManager
- Remove XTC cache prefix from Md5Utils
- Update web server and file browser to exclude XTC format
- Clear in-memory caches when disk cache is cleared
This commit is contained in:
cottongin
2026-01-27 20:35:32 -05:00
parent 158caacfe0
commit c2a966a6ea
30 changed files with 201 additions and 2624 deletions

View File

@@ -251,8 +251,8 @@ bool Epub::parseCssFiles() {
SdMan.remove(tmpCssPath.c_str());
}
Serial.printf("[%lu] [EBP] Loaded %zu CSS style rules from %zu files\n", millis(), cssParser->ruleCount(),
cssFiles.size());
Serial.printf("[%lu] [EBP] Loaded %zu CSS style rules from %zu files (~%zu bytes)\n", millis(), cssParser->ruleCount(),
cssFiles.size(), cssParser->estimateMemoryUsage());
return true;
}

View File

@@ -71,6 +71,25 @@ class CssParser {
*/
[[nodiscard]] size_t ruleCount() const { return rulesBySelector_.size(); }
/**
* Estimate memory usage of loaded rules (for debugging)
* Returns approximate bytes used by selector strings and style data
*/
[[nodiscard]] size_t estimateMemoryUsage() const {
size_t bytes = 0;
// unordered_map overhead: roughly 8 bytes per bucket + per-entry overhead
bytes += rulesBySelector_.bucket_count() * sizeof(void*);
for (const auto& entry : rulesBySelector_) {
// String storage: capacity + SSO overhead (~24 bytes) + actual chars
bytes += sizeof(std::string) + entry.first.capacity();
// CssStyle is ~16 bytes
bytes += sizeof(CssStyle);
// Per-entry node overhead in unordered_map (~24-32 bytes)
bytes += 32;
}
return bytes;
}
/**
* Clear all loaded rules
*/