The Record Advantage

So if records are just maps with some fields wired in, are they really worth the bother? As usual, the answer is it depends. One concrete advantage of records is that getting at the hard-wired fields is faster than getting at the equivalent fields in a map. Thus, if you had this:

 (​def​ irene {:name ​"Irene Adler"
  :appears-in ​"A Scandal in Bohemia"
  :author ​"Doyle"​})

you would expect that this would be faster:

 (:name watson)

than this:

 (:name irene)

How much faster? Certainly not enough to matter if you are only dealing with a few novels—or a few tens of thousands. But if you are dealing with seriously large mounds of data, the performance advantages of records are something to consider.

Another reason to use ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.