core.contracts

Make defconstrainedrecord's predicate fast

Details

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

Description

Instead of using the slow `clojure.core/type`, use an inlining function calling `instance?`. I have not tested the performance, but it's probably much faster.

  1. fast-predicate.diff
    06/Jun/13 7:48 AM
    2 kB
    Ambrose Bonnaire-Sergeant
  2. fast-predicate2.diff
    17/Jun/13 12:38 AM
    2 kB
    Ambrose Bonnaire-Sergeant

Activity

Hide
Ambrose Bonnaire-Sergeant added a comment -

These are the kinds of numbers I'm seeing between using type vs. instance? (220ms vs. 15ms).

Crude tests, but it should be obvious the inlining version is much faster.

user=> (time (dotimes [_ 1e6] (instance? Integer 1)))
"Elapsed time: 13.839681 msecs"
nil
user=> (time (dotimes [_ 1e6] (instance? Integer 1)))
"Elapsed time: 19.862729 msecs"
nil
user=> (time (dotimes [_ 1e6] (instance? Integer 1)))
"Elapsed time: 15.176552 msecs"
nil
user=> (time (dotimes [_ 1e6] (= Integer (type 1))))
"Elapsed time: 220.796493 msecs"
nil
user=> (time (dotimes [_ 1e6] (= Integer (type 1))))
"Elapsed time: 220.6573 msecs"
nil
user=> (time (dotimes [_ 1e6] (= Integer (type 1))))
"Elapsed time: 224.051327 msecs"
nil
Show
Ambrose Bonnaire-Sergeant added a comment - These are the kinds of numbers I'm seeing between using type vs. instance? (220ms vs. 15ms). Crude tests, but it should be obvious the inlining version is much faster.
user=> (time (dotimes [_ 1e6] (instance? Integer 1)))
"Elapsed time: 13.839681 msecs"
nil
user=> (time (dotimes [_ 1e6] (instance? Integer 1)))
"Elapsed time: 19.862729 msecs"
nil
user=> (time (dotimes [_ 1e6] (instance? Integer 1)))
"Elapsed time: 15.176552 msecs"
nil
user=> (time (dotimes [_ 1e6] (= Integer (type 1))))
"Elapsed time: 220.796493 msecs"
nil
user=> (time (dotimes [_ 1e6] (= Integer (type 1))))
"Elapsed time: 220.6573 msecs"
nil
user=> (time (dotimes [_ 1e6] (= Integer (type 1))))
"Elapsed time: 224.051327 msecs"
nil
Hide
Ambrose Bonnaire-Sergeant added a comment - - edited

Attached new patch: fast-predicate2.diff

Ensure instance? inlines. Needs to be put in a fn rather than definline.

There's a little benchmark. I noticed a speedup to 17ms for 1e6 iterations, from 185ms.

Show
Ambrose Bonnaire-Sergeant added a comment - - edited Attached new patch: fast-predicate2.diff Ensure instance? inlines. Needs to be put in a fn rather than definline. There's a little benchmark. I noticed a speedup to 17ms for 1e6 iterations, from 185ms.
Ambrose Bonnaire-Sergeant made changes -
Field Original Value New Value
Attachment fast-predicate2.diff [ 12034 ]
Hide
Fogus added a comment -

Applied on master. I will push a point-version out later today. Thanks.

Show
Fogus added a comment - Applied on master. I will push a point-version out later today. Thanks.
Fogus made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: