Skip SourceSpan in Binder Eq, Ord for faster exhaustivity check#3265
Skip SourceSpan in Binder Eq, Ord for faster exhaustivity check#3265kritzcreek merged 3 commits intopurescript:masterfrom bitemyapp:bitemyapp/dont-compare-source-span
Conversation
|
Thanks! |
|
Nice result! I'm wondering if it's be worth factoring this into the derived Also please don't forget to update |
|
I've added myself to
I'd hesitate for a couple reasons: This is personal preference and I realize I am probably slower to do this than is typical for the average PureScript contributor, but I don't like generalizing until I have at least 2 or 3 applications of the generalization I can evaluate. Is there an example anywhere else in the test suite of |
|
Looking at the exhaustiveness algorithm, we might be able to make it even more optimal if we use a |
|
@parsonsmatt that was the first approach I investigated and I think it was a good idea not to tackle that first. That's what I'm giving @MonoidMusician credit for helping me to avoid. Here's the current state of the flamegraph: See the skinny'ish tall tower on the left? Zooming in, it's still ordNub eating us alive in the exhaustiveness check: But it's still principally I think eliminating the nested lists of binders would be worth it iff it is the case that the number of times values are compared can be dramatically reduced by keeping them in a I'm going to try to keep the change localized to the exhaustiveness check but it still seems like a bit of a briar patch. I'll poke more but I'd like to see this change get in independent of anything else as it seems like an easy and big win. |
|
One suggestion I'd like to think about is if we could just make Eq and Ord on SourceSpans constantly return Eq. I doubt we ever want these spans to affect our equality checks. If that's too radical, maybe we can use a newtype wrapper that skips comparisons for usage within our AST data types. |
|
@kritzcreek I think that's a bad idea that doesn't have a GHC profile motivating it. If you don't actually want people to use an Eq or Ord instance, stop deriving them and fix all the code that implicitly depended upon them. Doing surprising things at runtime doesn't seem to me to be consistent with the design ethic I see in Haskell or PureScript. I do not think exceeding the changes of this PR WRT SourceSpans is a good use of time unless someone can point out an example of the source location information causing a performance problem elsewhere. |
|
Okay, yeah I think that's probably right. I was thinking about our |
|
I'd value a comment about how the derived instance is different. |
|
@puffnfresh Reasonable even if it's obvious what we're doing (dropping the source spans from the comparisons) -- rather leave a note explaining the purpose of the custom instance for posterity. I'll PR it later tonight. |


I get a speedup of about 17x for
LargeSumType.pursfrom this change. My curiosity was piqued by something @parsonsmatt mentioned while he was doing something unrelated.Optimized run went from 5 seconds to 0.29 seconds, profiled run went from 17 seconds to 1 second.
Here's a dump of some of what I was looking while optimizing this:
Before optimizing:
I found this flamegraph more helpful:
Big props to @MonoidMusician for pointing me in the right direction here.
Zooming in a couple parts of the main left block of the flamegraph:
After writing the custom Ord instance:
It's mostly disappeared from the flamegraph. Based on this and the human-readable
.profit seems like time is getting dominated by Parsec now.Normally I have moral objections to manual instances varying from derived instances but it isn't clear that incorporating the
SourceSpanintoBinder'sOrdorEqcomparisons would serve any purpose. I don't have a lot of choice with the exhaustivity checking usingOrdinstances as-written because thereordNubByisn't a thing for what are obvious reasons if you look at the implementation ofordNub. Any options for hacking around this seem more odious than the custom Eq/Ord. The speedup was purely from theOrdinstance but I did theEqinstance as well to harmonize its behavior withOrd.