-
Couldn't load subscription status.
- Fork 0
Optimize transitiveDirtyListBottomUpDiff using Pearce-Kelly algorithm for incremental topological ordering #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: soulomoon <[email protected]>
Co-authored-by: soulomoon <[email protected]>
|
|
||
| -- | Get all keys sorted by their topological order | ||
| getOrderedList :: TopoOrder -> STM [Key] | ||
| getOrderedList TopoOrder{..} = do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOrderedList is O(n log n), not good, it's better to keep an updated ordered list instead of computing it right at time. @copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed getOrderedList as it was not used anywhere and had O(n log n) complexity. The function is now eliminated from the API. (commit 6fb2e55)
| -- | Topological ordering structure for Pearce-Kelly algorithm | ||
| -- Maps each Key to its topological order number (smaller = earlier in order) | ||
| data TopoOrder = TopoOrder | ||
| { topoOrderMap :: !(TVar (Map.HashMap Key Int)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use StmContainers.Map here? @copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed TopoOrder to use StmContainers.Map instead of TVar (Map.HashMap ...). This is consistent with the rest of the codebase and provides better STM performance. (commit 6fb2e55)
…rderedList Co-authored-by: soulomoon <[email protected]>
Plan: Implement Pearce-Kelly algorithm for incremental topological ordering ✅ COMPLETE
The goal is to optimize
transitiveDirtyListBottomUpDiffby using the Pearce-Kelly algorithm to maintain a running topological order of the dependency graph.Implementation Plan
StmContainers.Mapinstead ofTVar (Map.HashMap ...)for better STM performancegetOrderedListfunction with O(n log n) complexityRecent Changes (Review Feedback)
Changed
TopoOrderto useStmContainers.Map:TVar (Map.HashMap Key Int)withSMap.Map Key IntreadTVar/writeTVaroperationsRemoved
getOrderedListfunction:Implementation Details
New Module: TopoSort.hs
Created a new module
Development.IDE.Graph.Internal.TopoSortimplementing the Pearce-Kelly algorithm:StmContainers.MapaddEdgeto incrementally update order when new dependencies are addedgetAffectedKeysInOrderto efficiently sort keys by topological orderUpdated Types.hs
Added
TopoOrderdata structure toSchedulerState:SMap.Map Key IntUpdated Database.hs
newDatabaseupdateReverseDepsto calladdEdgewhen dependencies changetransitiveDirtyListBottomUpDiffto usegetAffectedKeysInOrderfor efficient sortingPerformance Benefits
The Pearce-Kelly algorithm ensures that the topological order is maintained with minimal overhead during dependency updates, making
transitiveDirtyListBottomUpDifffaster especially for large dependency graphs.Testing
Files Changed
hls-graph/hls-graph.cabal- Added new module to exposed moduleshls-graph/src/Development/IDE/Graph/Internal/Types.hs- Added TopoOrder data structure using StmContainers.Maphls-graph/src/Development/IDE/Graph/Internal/TopoSort.hs- New module with Pearce-Kelly implementation, removed unused getOrderedListhls-graph/src/Development/IDE/Graph/Internal/Database.hs- Integration of topological orderinghls-graph/README.md- Documentation of the optimizationhls-graph/test/DatabaseSpec.hs- Fixed test warningsOriginal prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.