[racket] How can I speed up this code?

From: J G Cho (gcho at fundingmatters.com)
Date: Mon Jan 14 17:05:25 EST 2013

I am sorry if my email points the finger at json library. That was not
intentional. I think there could be other issues:

I did a onetime read of json and then wrote out as SEXP. I noticed the
slowness persisted despite that.

So then I wrote out only 1000 rows for the time being.

Here is the conversion code, which I am sure none of you needs but
incase there is some error in what I did.

(require json)

(define data-set
  (call-with-input-file "usagov_bitly_data.json"
    (lambda (in)
      (read-json in))))


(define (deep-ref dct keys)
  (if (empty? keys)
      dct
      (deep-ref (dict-ref dct
                          (first keys))
                (rest keys))))

(define cols
  (for/list ([col (deep-ref data-set '(meta view columns))])
    (dict-ref col 'name)))

(define rows
  (for/list ([row (dict-ref data-set
                            'data)])
     (map cons
          cols
          row)))


;; save a shorter list
(call-with-output-file "usagov_bitly_data.sexp"
  (lambda (out)
    (write (take rows 1000)
           out))
  #:exists 'replace)

Posted on the users mailing list.