Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Performance improvements #59

Merged
merged 1 commit into from
Mar 16, 2016
Merged

Conversation

natefaubion
Copy link
Contributor

This PR improves the performance across the board by better optimizing the sharing on pattern matches. There were a lot of duplicate checks for things like == and <= in guards. In my tests, about a 2x speedup overall. Ideally, a smarter pattern matcher could perform these optimizations, but for now we can do it manually.

lookup
insert
delete

@paf31
Copy link
Contributor

paf31 commented Mar 16, 2016

👍 Fantastic, thanks!

@jdegoes
Copy link
Contributor

jdegoes commented Mar 16, 2016

👍

lookup k (Three _ _ _ _ _ _ right) = lookup k right
lookup k tree =
let comp :: k -> k -> Ordering
comp = compare
Copy link
Member

Choose a reason for hiding this comment

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

I wasn't immediately sure why you did this at first, but I get it. Nice. I'll definitely do some work on this one day 😉

garyb added a commit that referenced this pull request Mar 16, 2016
@garyb garyb merged commit 59433d6 into purescript-deprecated:master Mar 16, 2016
@ethul
Copy link

ethul commented Mar 17, 2016

I just tried the 0.5.5 release and I am getting the following on psc 0.7.6.1:

Error found:
at /.../bower_components/purescript-maps/src/Data/Map.purs line 132, column 18 - line 132, column 18

  Unable to parse module:
  unexpected ,
  expecting ., {, number, char literal, string literal, "true", "false", [, _, "\\", qualifier, proper name, identifier, (, "case", "if", "do", "let", ::, operator or "of"

Was this a breaking change from 0.5.4?

@garyb
Copy link
Member

garyb commented Mar 17, 2016

Argh, it wasn't supposed to be. Looks like it's the multi-valued case, I thought that went in before 0.8.

@natefaubion perhaps we should use a record/array literal there for now, and then remove again when we make the release for psc 0.8?

@garyb
Copy link
Member

garyb commented Mar 17, 2016

I've just reverted it for now, I did a version using records and arrays but then was greeted by a bunch of partial pattern warnings. Perhaps there is something we can do pre-0.8 still though.

@natefaubion
Copy link
Contributor Author

I thought that went in before 0.8.

I would have sworn that as well.

I think records should work (you're just doing useless allocations :/). Arrays will always give you the partial warnings. You could also use other functions, but that may be slower since you can't use mkFn, so you'd have the overhead of more currying.

@natefaubion
Copy link
Contributor Author

Both lookup and insert can be rewritten with single case matching with slightly more verbose branching, but delete cannot. Swapping out the multi-case for objects actually makes it about twice as slow as the current delete. There are fewer perf wins for delete, so if we want to make these perf changes compatible for 0.7.6, then should probably just leave delete as is.

Do we want to update lookup and insert as a 0.5.x change, and then fix warnings + delete for a 0.6 change?

@garyb
Copy link
Member

garyb commented Mar 18, 2016

Sounds good to me, thanks for looking into this again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants