fix: resolve hledger-ui --watch memory leak and CPU hogging (#1825)#2594
Open
bomlinux92-byte wants to merge 4 commits into
Open
fix: resolve hledger-ui --watch memory leak and CPU hogging (#1825)#2594bomlinux92-byte wants to merge 4 commits into
bomlinux92-byte wants to merge 4 commits into
Conversation
…hael#1825) Port of alerque's PR simonmichael#2473 with fixes for the memory leak and CPU consumption issues in hledger-ui --watch mode. Root cause: - Haskell's lazy evaluation was retaining thunks (unevaluated expressions) from previous data states, causing memory to grow indefinitely with each reload - The old regenerateScreens was reusing the same UIState record, which kept old thunk chains alive - The transaction screen was not updating when data changed Fix: - Force evaluation of new data structures at reload time so the old ones can be garbage collected - regenerateScreens now uses strict field updates (!) to ensure new data structures are fully evaluated - Register screen now calls regenerateScreens after reload - Transaction screen now properly updates to show the current transaction data after a reload - Display items in register screen are now strictly evaluated Files changed: - hledger-ui/Hledger/UI/UIState.hs: Strict regeneration of screens - hledger-ui/Hledger/UI/UIScreens.hs: Strict evaluation in rsUpdate and tsUpdate, live updating for transaction page - hledger-ui/Hledger/UI/RegisterScreen.hs: Call regenerateScreens after uiReload - hledger-ui/Hledger/UI/TransactionScreen.hs: Proper update logic - hledger-ui/hledger-ui.m4.md: Removed documentation of the bug Closes simonmichael#1825
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix for [BOUNTY $150 x 3 platforms] hledger-ui --watch consumes more CPU and RAM over time — Issue #1825
Root cause
Haskell's lazy evaluation was retaining thunks (unevaluated expressions) from previous data states. Each time reloaded the journal, the old UI state data structures were kept alive because:
seqinstead of actually updatingThis caused memory to grow indefinitely (one thunk chain per reload), and CPU to accumulate because the Haskell runtime kept accumulating work.
Fix (ported from alerque's PR #2473)
regenerateScreensnow uses strict field updates () to force evaluation of new data structures, allowing old ones to be garbage collectedregenerateScreensafteruiReloadto ensure all screens are properly refreshedChanges
Testing
grepeatedly while watching memory usage — old version grows unboundedly, new version stabilizesCloses #1825