db/sqlite3: use {start,end}-atomic instead of call-as-atomic
On my machine, this reduces the running time of the sqlite3 tests by about 1/4 (~3.2s to ~2.4s). Other things I tried that didn't make as big a difference: - coalesce A regions - fast path for call-with-lock
This commit is contained in:
parent
2df51c4d19
commit
e9f2c084eb
|
@ -51,11 +51,12 @@
|
||||||
;; Custodian shutdown can cause disconnect even in the middle of
|
;; Custodian shutdown can cause disconnect even in the middle of
|
||||||
;; operation (with lock held). So use (A _) around any FFI calls,
|
;; operation (with lock held). So use (A _) around any FFI calls,
|
||||||
;; check still connected.
|
;; check still connected.
|
||||||
|
;; Optimization: use faster {start,end}-atomic instead of call-as-atomic;
|
||||||
|
;; but must not raise exn within (A _)!
|
||||||
(define-syntax-rule (A e ...)
|
(define-syntax-rule (A e ...)
|
||||||
(call-as-atomic
|
(begin (start-atomic)
|
||||||
(lambda ()
|
(unless -db (end-atomic) (error/disconnect-in-lock 'sqlite3))
|
||||||
(unless -db (error/disconnect-in-lock 'sqlite3))
|
(begin0 (let () e ...) (end-atomic))))
|
||||||
e ...)))
|
|
||||||
|
|
||||||
(define/private (get-db fsym)
|
(define/private (get-db fsym)
|
||||||
(or -db (error/not-connected fsym)))
|
(or -db (error/not-connected fsym)))
|
||||||
|
@ -211,18 +212,18 @@
|
||||||
(HANDLE fsym
|
(HANDLE fsym
|
||||||
;; Do not allow break/kill between prepare and
|
;; Do not allow break/kill between prepare and
|
||||||
;; entry of stmt in table.
|
;; entry of stmt in table.
|
||||||
(A (let-values ([(prep-status stmt tail?)
|
((A (let-values ([(prep-status stmt tail?)
|
||||||
(sqlite3_prepare_v2 db sql)])
|
(sqlite3_prepare_v2 db sql)])
|
||||||
(cond [(not (zero? prep-status))
|
(cond [(not (zero? prep-status))
|
||||||
(when stmt (sqlite3_finalize stmt))
|
(when stmt (sqlite3_finalize stmt))
|
||||||
(values prep-status #f)]
|
(lambda () (values prep-status #f))]
|
||||||
[tail?
|
[tail?
|
||||||
(when stmt (sqlite3_finalize stmt))
|
(when stmt (sqlite3_finalize stmt))
|
||||||
(error* fsym "multiple statements given"
|
(lambda () ;; escape atomic mode (see A)
|
||||||
'("given" value) sql)]
|
(error fsym "multiple statements given\n value: ~e" sql))]
|
||||||
[else
|
[else
|
||||||
(when stmt (hash-set! stmt-table stmt #t))
|
(when stmt (hash-set! stmt-table stmt #t))
|
||||||
(values prep-status stmt)]))))])
|
(lambda () (values prep-status stmt))])))))])
|
||||||
(when DEBUG?
|
(when DEBUG?
|
||||||
(dprintf " << prepared statement #x~x\n" (cast stmt _pointer _uintptr)))
|
(dprintf " << prepared statement #x~x\n" (cast stmt _pointer _uintptr)))
|
||||||
(unless stmt (error* fsym "SQL syntax error" '("given" value) sql))
|
(unless stmt (error* fsym "SQL syntax error" '("given" value) sql))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user