I don't think I'll go with primitive arrays. A big part of the reason I'm using Clojure is for the immutable persistence. I just want to use them in the most efficient way possible. I know I'm not going to get hyper-blazing C-level performance.
On Wednesday, 20 April 2016 15:38:11 UTC-7, Stuart Sierra wrote: > > The first answer: test & measure. Benchmark your code, use a JVM profiler > to find hotspots, etc. Test every change you make to see if it has a > measurable improvement. Any assumptions about what “should” be > faster/slower are likely to be wrong. > > The long answer: > > The JVM does not give you much control over how objects are arranged in > memory. In Java and Clojure, almost everything is a pointer to an object on > the heap. Java collection classes and Clojure collections store pointers to > objects; they do not store values “in-line” like an array of structs in C. > The JVM *may* have optimizations that try to arrange objects “near” other > objects, but you have no control over this. > > So my (untested) expectation is that all Clojure collection types are > more-or-less equal in terms of memory locality. > > The only built-in data structure that offers the possibility of contiguous > allocation in Java — without dropping down to native code — is an array of > primitives, such as integers or doubles. Clojure has built-in functions to > create and manipulate Java primitive arrays, if that works for your use > case. > > –S > > > On Wednesday, April 20, 2016 at 2:03:10 PM UTC-4, JvJ wrote: >> >> I'm writing some code that I would like to perform as quickly as >> possible. Currently, I am iterating over large hash maps and performing >> assocs and dissocs. >> >> I don't know much about performance optimization, but I am told that >> memory locality is a big factor. I would like to know how Persistent Maps, >> Persistent Vectors, Transient Maps, and Transient Vectors compare to one >> another in this respect. >> >> Also, the objects in the collection that I'm iterating over will >> themselves be maps. So, if I had a vector with good memory locality, but >> it stored what are effectively pointers to maps allocated elsewhere, will >> that nullify the benefits of memory locality? >> >> Thanks >> > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
