<< Back to previous view

[CCONTRACTS-1] Make defconstrainedrecord's predicate fast Created: 06/Jun/13  Updated: 28/Jun/13  Resolved: 28/Jun/13

Status: Resolved
Project: core.contracts
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Trivial
Reporter: Ambrose Bonnaire-Sergeant Assignee: Fogus
Resolution: Completed Votes: 0
Labels: None

Attachments: File fast-predicate2.diff     File fast-predicate.diff    

 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.



 Comments   
Comment by Ambrose Bonnaire-Sergeant [ 16/Jun/13 11:17 AM ]

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
Comment by Ambrose Bonnaire-Sergeant [ 17/Jun/13 12:38 AM ]

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.

Comment by Fogus [ 28/Jun/13 8:11 AM ]

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

Generated at Fri Nov 28 12:17:20 CST 2014 using JIRA 4.4#649-r158309.