Use CJSON to read JSON
Profiling shows that most time is spent in: - medea#read-json - chicken.port#with-input-from-string Use the cjson egg to read JSON to go a lot faster. Note that we still write JSON using medea; that's not slow. Thanks to wasamasa and sjamaan on #chicken for profiling tips.
This commit is contained in:
parent
950d974f67
commit
bfb9974aa9
|
@ -8,7 +8,7 @@
|
||||||
(license "MIT")
|
(license "MIT")
|
||||||
(author "Lassi Kortela")
|
(author "Lassi Kortela")
|
||||||
(maintainer "Lassi Kortela")
|
(maintainer "Lassi Kortela")
|
||||||
(dependencies http-client medea scsh-process)
|
(dependencies cjson http-client medea scsh-process)
|
||||||
(test-dependencies)
|
(test-dependencies)
|
||||||
(distribution-files
|
(distribution-files
|
||||||
"pandoc.server.chicken.scm"
|
"pandoc.server.chicken.scm"
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
(import (scheme)
|
(import (scheme)
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
(cjson)
|
||||||
(only (chicken port) with-input-from-string)
|
(only (chicken port) with-input-from-string)
|
||||||
(only (chicken io) read-string)
|
(only (chicken io) read-string)
|
||||||
(only (http-client) with-input-from-request)
|
(only (http-client) with-input-from-request)
|
||||||
|
@ -37,9 +38,17 @@
|
||||||
(cons 'text input-string)))
|
(cons 'text input-string)))
|
||||||
input-strings)))))
|
input-strings)))))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(map (lambda (string)
|
(let ((array (string->cjson (read-string))))
|
||||||
(with-input-from-string string read-json))
|
(unless (eq? cjson/array (cjson-type array))
|
||||||
(vector->list (read-json))))))
|
(error "Got unexpected JSON from pandoc-server"))
|
||||||
|
(let loop ((i (- (cjson-array-size array) 1)) (results '()))
|
||||||
|
(if (< i 0) results
|
||||||
|
(loop (- i 1)
|
||||||
|
(cons (cjson-schemify
|
||||||
|
(string->cjson
|
||||||
|
(cjson-schemify
|
||||||
|
(cjson-array-ref array i))))
|
||||||
|
results))))))))
|
||||||
|
|
||||||
(define (pandoc-server-files->json input-format input-filenames)
|
(define (pandoc-server-files->json input-format input-filenames)
|
||||||
(pandoc-server-strings->json
|
(pandoc-server-strings->json
|
||||||
|
|
Loading…
Reference in New Issue