<< Back to previous view

[CCACHE-27] Missing LU and LRU is linear complexity - performance Created: 04/Sep/12  Updated: 22/Mar/16  Resolved: 22/Mar/16

Status: Closed
Project: core.cache
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Ghadi Shayban Assignee: Fogus
Resolution: Completed Votes: 0
Labels: enhancement, performance

Mac Oracle JDK, Linux OpenJDK

Attachments: Text File priority-map-fixed.patch     Text File priority-map.patch    
Patch: Code


Profiling some code with YourKit showed a hotspot in cache statistics on (miss) for LU and LRU caches.

Basically two issues: (count (keys {....})) is a count of a seq, not efficient. Replaced with a count of the map.

Secondly, (apply f anything) is slow. Profiler showed that the (apply min-key) was really slow. This is mitigated by using a c.d.priority-map instead. On a priority-map, (ffirst {}) or (first (peek {}).

Also inverted the logic for threshold comparison. Since there is a (build-leastness-queue) that populates statistics, should caches should favor codepaths for the state of being full all the time?

Comment by Ghadi Shayban [ 06/Sep/12 10:49 PM ]

I take back the part about (apply) being slow. I think it's more the fact that it's doing a linear scan on keys every single time.

(apply) does show up a lot in a profiler, but I haven't figured out why. (apply + (range big)) seems to even be slightly faster than (reduce +) on the same range.

Comment by Ghadi Shayban [ 12/Sep/12 9:27 AM ]

Patch in proper format

Comment by Alex Miller [ 22/Mar/16 10:38 AM ]

This was committed in https://github.com/clojure/core.cache/commit/3b48810176c42e0ffd91e9d05b6c7be83b3490f3 but this issue was never closed.

Generated at Tue Jan 23 14:13:46 CST 2018 using JIRA 4.4#649-r158309.