code-reviews

2019-03-19T09:25:47.010700Z

hi all, I’m profiling some code in a tight loop, it seems that I’m creating alot of maps. Any advice on perf optimizations? I thought about either using records or volatile-mutable

2019-03-19T09:49:29.011900Z

have you tried transients?

jumar 2019-03-19T09:50:05.012200Z

that was my idea too => see https://clojure.org/reference/transients

jumar 2019-03-19T09:51:02.013Z

or perhaps you can get rid of excessive objects creation by changing your algorithm / using different data structures.

2019-03-19T15:28:52.013900Z

Tried transients, it gives a small improv but the very best is volatible mutable

2019-03-19T15:29:00.014200Z

records dont give alot of improvement

seancorfield 2019-03-19T16:38:13.015Z

@mping Have you also confirmed there is no reflection or boxing/unboxing?

2019-03-19T16:39:03.015300Z

@seancorfield yep, that fixed it quite a bit

2019-03-19T16:39:21.015700Z

we use destructuring alot , so we end up passing maps around to supply fn arguments

2019-03-19T16:39:49.016300Z

according to my completely unscientific benchmark, defrecord is just a bit better than plain maps

2019-03-19T17:25:46.016700Z

records wouldn't actually help here - they are just maps with more methods on them

2019-03-19T17:26:28.017200Z

also destructuring is more expensive than just using maps, I'd never destructure in a tight loop

chrisulloa 2019-03-19T18:06:34.017500Z

i thought records did provide better performance than a plain map

2019-03-19T18:08:39.017900Z

oh, for the defined fields, yes, thanks for the reminder