core.match

perf 3x slower for ragged rows

Details

  • Type: Enhancement Enhancement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

In both cases, match should fail immediately on seeing the first element.

Slow case:

(let [f
        (fn [x] (match x [1 1] 1 [2] 2 :else 3))]
    (time (dotimes [_ 100000] (f [3]))))
"Elapsed time: 57.899 msecs"

Fast case:

(let [f
        (fn [x] (match x [1 1] 1 [2 _] 2 :else 3))]
    (time (dotimes [_ 100000] (f [3]))))
"Elapsed time: 16.998 msecs"

Activity

David Nolen made changes -
Field Original Value New Value
Priority Major [ 3 ] Minor [ 4 ]
Issue Type Defect [ 1 ] Enhancement [ 4 ]
Hide
David Nolen added a comment -

Ragged rows are hard to optimize. We used to try and intelligently group patterns - but this "optimization" created an incredible number of edgecase bugs. So until I or someone else can come up with a sound way to do this, going to continue to punt on this.

Show
David Nolen added a comment - Ragged rows are hard to optimize. We used to try and intelligently group patterns - but this "optimization" created an incredible number of edgecase bugs. So until I or someone else can come up with a sound way to do this, going to continue to punt on this.
David Nolen made changes -
Description In both cases, match should fail immediately on seeing the first element.

Slow case:

(let [f
        (fn [x] (match x [1 1] 1 [2] 2 :else 3))]
    (time (dotimes [_ 100000] (f [3]))))
"Elapsed time: 57.899 msecs"

Fast case:

 (let [f
        (fn [x] (match x [1 1] 1 [2 _] 2 :else 3))]
    (time (dotimes [_ 100000] (f [3]))))
"Elapsed time: 16.998 msecs"


In both cases, match should fail immediately on seeing the first element.

Slow case:

{code}
(let [f
        (fn [x] (match x [1 1] 1 [2] 2 :else 3))]
    (time (dotimes [_ 100000] (f [3]))))
"Elapsed time: 57.899 msecs"
{code}

Fast case:

{code}
 (let [f
        (fn [x] (match x [1 1] 1 [2 _] 2 :else 3))]
    (time (dotimes [_ 100000] (f [3]))))
"Elapsed time: 16.998 msecs"
{code}


Hide
kovas boguta added a comment -

Can you point commit where that optimization existed? Just want to get a sense of what code path are affected.

Show
kovas boguta added a comment - Can you point commit where that optimization existed? Just want to get a sense of what code path are affected.
Hide
David Nolen added a comment - - edited

If you look at the repo tree around the first 0.2.0 alpha you'll see it, however the optimization was not global - it was a specific thing for each type of pattern. Again, I'm not particularly inclined to revisit this myself, but if you have a clever idea how it can be done without the previous problems I'm all for it.

Show
David Nolen added a comment - - edited If you look at the repo tree around the first 0.2.0 alpha you'll see it, however the optimization was not global - it was a specific thing for each type of pattern. Again, I'm not particularly inclined to revisit this myself, but if you have a clever idea how it can be done without the previous problems I'm all for it.
Hide
David Nolen added a comment -

Not fixing this.

Show
David Nolen added a comment - Not fixing this.
David Nolen made changes -
Resolution Declined [ 2 ]
Status Open [ 1 ] Resolved [ 5 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: