On Dec 21, 2012, at 5:22 PM, Marshall Bockrath-Vandegrift wrote:
> Not to the bottom of things yet, but found some low-hanging fruit –
> switching the `push-state` from a struct-map to a record gives a flat
> ~2x speedup in all configurations I tested.  So, that’s good?

I really appreciate your attention to this Marshall.

FWIW I used records for push-states at one point but did not observe a speedup 
and it required much messier code, so I reverted to struct-maps. But maybe I 
wasn't doing the right timings. I'm curious about how you changed to records 
without the messiness. I'll include below my sig the way that I had to do it... 
maybe you can show me what you did instead.

Still, I guess the gorilla in the room, which is eating the multicore 
performance, hasn't yet been found.

 -Lee

--- tl;dr: the structs vs. records thing ---

Here's how I do what I need to do with struct-maps:

;; this is defined elsewhere, and I want push-states to have fields for each 
push-type that's defined here
(def push-types '(:exec :integer :float :code :boolean :string :zip
                        :tag :auxiliary :return :environment)

;; so I use a macro to produce the struct-map definition
(defmacro define-push-state-structure []
  `(defstruct push-state ~@push-types))

;; call the macro to define the struct
(define-push-state-structure)

;; and then when I want a new push-state I can just call struct-map:
(defn make-push-state
  "Returns an empty push state."
  []
  (struct-map push-state))

In order to do the same thing with records I had to resort to this:

(defn keyword->symbol [kwd]
  "Returns the symbol obtained by removing the : from a keyword."
  (read-string (name kwd)))

(defmacro define-push-state-record-type []
  "Defines the pushstate record type. The odd trick with read-string was a hack 
to 
avoid namespace qualification on the pushstate symbol."
  `(defrecord ~(read-string "pushstate") [~@(map keyword->symbol push-types)]))

(define-push-state-record-type)

(defmacro make-push-state
  "Returns an empty push state."
  []
  `(pushstate. ~@(map (fn [_] nil) push-types)))

Is there a much simpler way that I overlooked?




-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to