Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAlgoritmic improvement in Dict #350
Conversation
jvoigtlaender
added some commits
Aug 15, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Awesome, I like this one a lot more, nice refactor! |
pushed a commit
that referenced
this pull request
Aug 16, 2015
evancz
merged commit 1106463
into
elm:master
Aug 16, 2015
1 check passed
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Aug 16, 2015
Member
Let's get rid of min in a PR of its own.
I don't know the code well enough to say on the second one. if you think it's better, it makes sense to me to try it.
|
Let's get rid of I don't know the code well enough to say on the second one. if you think it's better, it makes sense to me to try it. |
jvoigtlaender
deleted the
jvoigtlaender:dict
branch
Aug 16, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Aug 16, 2015
Contributor
PR for removing min: https://github.com/elm-lang/core/pull/351
About the other potential change (merging maxWithDefault and remove_max), this would really require first having some benchmarking in place. The idea would be to use a classic tupling transformation. That is,
maxWithDefault : k -> v -> Dict k v -> (k, v)and
remove_max : NColor -> k -> v -> Dict k v -> Dict k v -> Dict k vwould be replaced by
new_function : NColor -> k -> v -> Dict k v -> Dict k v -> ((k, v), Dict k v)with the understanding that semantically
new_function c k v l r = (maxWithDefault k v r, remove_max c k v l r)but actually new_function performs only one traversal instead of the two independent traversals of remove_max and maxWithDefault.
In theory, this transformation should always be an improvement, but in practice it shows (at the very least in Haskell, partly due to issues with laziness) that very often it is not. The extra tuples may lead to space overhead, extra construction and deconstruction work, etc.
|
PR for removing About the other potential change (merging maxWithDefault : k -> v -> Dict k v -> (k, v)and remove_max : NColor -> k -> v -> Dict k v -> Dict k v -> Dict k vwould be replaced by new_function : NColor -> k -> v -> Dict k v -> Dict k v -> ((k, v), Dict k v)with the understanding that semantically new_function c k v l r = (maxWithDefault k v r, remove_max c k v l r)but actually In theory, this transformation should always be an improvement, but in practice it shows (at the very least in Haskell, partly due to issues with laziness) that very often it is not. The extra tuples may lead to space overhead, extra construction and deconstruction work, etc. |
jvoigtlaender commentedAug 15, 2015
Replaces https://github.com/elm-lang/core/pull/255.
The essence is that calls
max (RBNode_elm_builtin c k v l r)are replaced bymaxWithDefault k v r, where the improvement is that the latter function is less complicated (fewer arguments, less pattern matching) and does not need an artificial (never triggered)Debug.crashcase.Two further notes:
minis never called, also not exported, thus could be eliminated.maxWithDefaultandremove_maxare always called in parallel, and have the same recursion structure, so could in principle be merged into a single function.