Skip to content
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

Optimize the implementation of Graph.listParents #209

Merged
merged 2 commits into from May 6, 2021

Conversation

mitchellwrosen
Copy link
Collaborator

This PR optimizes the implementation of Graph.listParents. I'll annotate the PR with some comments.

@@ -5,7 +5,14 @@
------------------------------------------------------------------------------}
{-# language ScopedTypeVariables#-}

module Reactive.Banana.Prim.Graph where
module Reactive.Banana.Prim.Graph
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To make sure some invariants are not violated, made Graph an opaque type to the rest of the codebase.

@@ -18,8 +25,19 @@ import Data.Maybe
Graphs and topological sorting
------------------------------------------------------------------------------}
data Graph a = Graph
{ children :: Map.HashMap a [a]
{ -- | The mapping from each node to the set of nodes reachable by an out-edge. If a node has no out-edges, it is
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just a bit of documentation about how this particular flavor of directed graph representation works.

@@ -47,9 +65,9 @@ getParents gr x = maybe [] id . Map.lookup x . parents $ gr
listParents :: forall a. (Eq a, Hashable a) => Graph a -> [a]
listParents gr = list
where
-- all nodes without children
-- all nodes without parents
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm pretty sure this was just a confusing typo, and not a bug in the implementation. We keep nodes that have no parents with this computation:

[ x | x <- Set.toList $ nodes gr, null (getParents gr x)]

@mitchellwrosen
Copy link
Collaborator Author

Hmm... uh, CI looks broken. I guess that's my fault due to #207...?

Seems like the line echo "$HOME/.ghcup/ghc/8.10.3/bin" >> $GITHUB_PATH isn't working, when running cabal build the globally-installed GHC (apparently 9.0) is being picked up.

@mitchellwrosen
Copy link
Collaborator Author

A previous build seems to have worked.

https://github.com/HeinrichApfelmus/reactive-banana/runs/2369884533?check_suite_focus=true#step:12:5

I guess something's gone wrong with the caching.

@mitchellwrosen
Copy link
Collaborator Author

Heh, well I tried to fix CI in #210, made no progress, and just smuggled in the nuclear option to this PR, which is to take the ~1m hit to install GHC on every run, because caching ~/.ghcup wasn't working, and I couldn't figure out why.

I'll move that commit over to #210 and merge that for now.

@mitchellwrosen
Copy link
Collaborator Author

Ready for review 👍

@HeinrichApfelmus
Copy link
Owner

Looks good, thanks! I have added a suggestion. Not sure what happens if I click the "Commit suggestion" button. 🤔 Could you include it? Then feel free to merge. 😊

Co-authored-by: Heinrich Apfelmus <apfelmus@quantentunnel.de>
@mitchellwrosen mitchellwrosen merged commit ca5c05f into master May 6, 2021
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.

None yet

2 participants