Clojure

Add InternalReduce

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.2
  • Component/s: None
  • Labels:
    None
  • Approval:
    Ok

Description

InternalReduce protocol lets seqs take advantage of structural details, make reduce run faster.

Activity

Hide
Assembla Importer added a comment -

stu said: [file:a45y7yqser379teJe5aVNr]: internal-reduce

Show
Assembla Importer added a comment - stu said: [file:a45y7yqser379teJe5aVNr]: internal-reduce
Hide
Assembla Importer added a comment -

liwp said: Stuart,

Great stuff!

You could move the (alength arr) call in arr-impl from the loop form to the let-binding to avoid it getting called on each iteration.

– Lauri

Show
Assembla Importer added a comment - liwp said: Stuart, Great stuff! You could move the (alength arr) call in arr-impl from the loop form to the let-binding to avoid it getting called on each iteration. – Lauri
Hide
Assembla Importer added a comment -

khinsen said: This looks like a very good idea!

Question: would it be preferable to pass the original coll to internal-reduce, rather than (seq coll)?

Advantages:

  • no need to create a seq before doing a reduce
  • more potential for optimization if the coll can implement reduce faster directly and the associated seq does not permit to retrieve the coll.

Disadvantage:

  • reduce needs to be implemented for seqs anyway, so the number of implementations would increase.

Konrad

Show
Assembla Importer added a comment - khinsen said: This looks like a very good idea! Question: would it be preferable to pass the original coll to internal-reduce, rather than (seq coll)? Advantages:
  • no need to create a seq before doing a reduce
  • more potential for optimization if the coll can implement reduce faster directly and the associated seq does not permit to retrieve the coll.
Disadvantage:
  • reduce needs to be implemented for seqs anyway, so the number of implementations would increase.
Konrad
Hide
Assembla Importer added a comment -

stu said: Lauri,

I tried lifting the alength calls and the code runs slightly slower (in my unscientific tests on a single laptop. Counterintuitive, huh?

Stu

Show
Assembla Importer added a comment - stu said: Lauri, I tried lifting the alength calls and the code runs slightly slower (in my unscientific tests on a single laptop. Counterintuitive, huh? Stu
Hide
Assembla Importer added a comment -

stu said: Konrad,

The chunking support is on seqs, and it is fast. Also the seq-before-reduce localizes the nil/empty check in reduce. I think Rich had another reason too but I can't remember what it was.

Stu

Show
Assembla Importer added a comment - stu said: Konrad, The chunking support is on seqs, and it is fast. Also the seq-before-reduce localizes the nil/empty check in reduce. I think Rich had another reason too but I can't remember what it was. Stu
Hide
Assembla Importer added a comment -

stu said: Updating tickets (#289, #298)

Show
Assembla Importer added a comment - stu said: Updating tickets (#289, #298)

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: