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:
Lassi Kortela 2021-09-01 15:31:49 +03:00
parent 950d974f67
commit bfb9974aa9
2 changed files with 13 additions and 4 deletions

View File

@ -8,7 +8,7 @@
(license "MIT")
(author "Lassi Kortela")
(maintainer "Lassi Kortela")
(dependencies http-client medea scsh-process)
(dependencies cjson http-client medea scsh-process)
(test-dependencies)
(distribution-files
"pandoc.server.chicken.scm"

View File

@ -8,6 +8,7 @@
(import (scheme)
(chicken base)
(cjson)
(only (chicken port) with-input-from-string)
(only (chicken io) read-string)
(only (http-client) with-input-from-request)
@ -37,9 +38,17 @@
(cons 'text input-string)))
input-strings)))))
(lambda ()
(map (lambda (string)
(with-input-from-string string read-json))
(vector->list (read-json))))))
(let ((array (string->cjson (read-string))))
(unless (eq? cjson/array (cjson-type array))
(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)
(pandoc-server-strings->json