Liking cljdoc? Tell your friends :D

Performance

performance/assoc-many

Enabled by defaultVersion AddedVersion Updated
false1.10.01.10.0

Assoc takes multiple pairs but relies on seq stepping. This is slower than relying on multiple assoc invocations.

Examples

; avoid
(assoc m :k1 1 :k2 2 :k3 3)

; prefer
(-> m
    (assoc :k1 1)
    (assoc :k2 2)
    (assoc :k3 3))

performance/avoid-satisfies

Enabled by defaultVersion AddedVersion Updated
false1.10.01.10.0

Avoid use of satisfies? as it is extremely slow. Restructure your code to rely on protocols or other polymorphic forms.

Examples

; avoid
(satisfies? Foo :bar)

Reference


performance/dot-equals

Enabled by defaultVersion AddedVersion Updated
false1.111.11

= is quite generalizable and built to handle immutable data. When using a literal, it can be significantly faster to use the underlying Java method.

Currently only checks string literals.

If lint/prefer-method-values is enabled, then the suggestion will use that syntax.

Examples

; avoid
(= "foo" s)

; prefer
(.equals "foo" s)
(String/equals "foo" s)

performance/get-in-literals

Enabled by defaultVersion AddedVersion Updated
false1.10.01.10.0

clojure.core/get-in is both polymorphic and relies on seq stepping, which has heavy overhead when the listed slots are keyword literals. Faster to call them as functions.

Examples

; avoid
(get-in m [:some-key1 :some-key2 :some-key3])

; prefer
(-> m :some-key1 :some-key2 :some-key3)

performance/get-keyword

Enabled by defaultVersion AddedVersion Updated
false1.10.01.10.0

clojure.core/get is polymorphic and overkill if accessing a map with a keyword literal. The fastest is to fall the map itself as a function but that requires a nil check, so the safest fast method is to use the keyword as function.

Examples

; avoid
(get m :some-key)

; prefer
(:some-key m)

performance/into-transducer

Enabled by defaultVersion AddedVersion Updated
false1.111.11

into has a 3-arity and a 4-arity form. Both pour the given coll into the new coll but when given a transducer in the 4-arity form, the transducer is efficiently applied in between.

Examples

; avoid
(into [] (map inc (range 100)))

; prefer
(into [] (map inc) (range 100))

Reference


performance/single-literal-merge

Enabled by defaultVersion AddedVersion Updated
false1.111.11

clojure.core/merge is inherently slow. Its major benefit is handling nil values. If there is only a single object to merge in and it's a map literal, that benefit is doubly unused. Better to directly assoc the values in.

NOTE: If the chosen style is :single and performance/assoc-many is enabled, the style will be treated as :multiple to make the warnings consistent.

Examples

; avoid
(merge m {:a 1 :b 2 :c 3})

; prefer
(assoc m :a 1 :b 2 :c 3)

Configurable Attributes

NameDefaultOptions
:chosen-style:single:single, :multiple

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close