some further optimizations

db4
Sascha Matzke 2009-03-25 21:33:39 +01:00
parent b57cdefde0
commit a050578c3b
3 changed files with 36 additions and 33 deletions

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs bson.constants byte-arrays byte-vectors
calendar fry io io.binary io.encodings io.encodings.string io.encodings.private
io.encodings.utf8 kernel math math.parser namespaces quotations
io.encodings.utf8.private io.encodings.utf8 kernel math math.parser namespaces quotations
sequences sequences.private serialize strings tools.walker words ;
@ -22,6 +22,13 @@ CONSTANT: INT64-SIZE 8
shared-buffer get
[ 8192 <byte-vector> [ shared-buffer set ] keep ] unless* ; inline
: >le-stream ( x n -- )
! >le write
swap '[ _ swap nth-byte 0 B{ 0 }
[ set-nth-unsafe ] keep write ] each
; inline
PRIVATE>
: reset-buffer ( buffer -- )
@ -74,12 +81,14 @@ M: objref bson-type? ( objref -- type ) drop T_Binary ;
M: quotation bson-type? ( quotation -- type ) drop T_Binary ;
M: byte-array bson-type? ( byte-array -- type ) drop T_Binary ;
: write-utf8-string ( string -- ) output-stream get utf8 encoder-write ; inline
: write-byte ( byte -- ) CHAR-SIZE >le write ; inline
: write-int32 ( int -- ) INT32-SIZE >le write ; inline
: write-double ( real -- ) double>bits INT64-SIZE >le write ; inline
: write-cstring ( string -- ) write-utf8-string B{ 0 } write ; inline
: write-longlong ( object -- ) INT64-SIZE >le write ; inline
: write-utf8-string ( string -- )
output-stream get '[ _ swap char>utf8 ] each ; inline
: write-byte ( byte -- ) CHAR-SIZE >le-stream ; inline
: write-int32 ( int -- ) INT32-SIZE >le-stream ; inline
: write-double ( real -- ) double>bits INT64-SIZE >le-stream ; inline
: write-cstring ( string -- ) write-utf8-string 0 write-byte ; inline
: write-longlong ( object -- ) INT64-SIZE >le-stream ; inline
: write-eoo ( -- ) T_EOO write-byte ; inline
: write-type ( obj -- obj ) [ bson-type? write-byte ] keep ; inline

View File

@ -254,23 +254,23 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
: run-benchmarks ( -- )
"db" "db" get* "host" "127.0.0.1" get* "port" 27020 get* ensure-number <mdb>
[ ensure-buffer
print-header
! insert
! { small-doc-prepare medium-doc-prepare
{ large-doc-prepare }
{ { } { index } { errcheck } { index errcheck }
{ batch } { batch errcheck } { batch index errcheck }
} run-insert-bench
! find-one
! { small-doc medium-doc large-doc }
! { { } { index } } run-find-one-bench
! find-all
! { small-doc medium-doc large-doc }
! { { } { index } } run-find-all-bench
! find-range
! { small-doc medium-doc large-doc }
! { { } { index } } run-find-range-bench
[ ensure-buffer
print-header
! insert
{ small-doc-prepare medium-doc-prepare
large-doc-prepare }
{ { } { index } { errcheck } { index errcheck }
{ batch } { batch errcheck } { batch index errcheck }
} run-insert-bench
! find-one
{ small-doc medium-doc large-doc }
{ { } { index } } run-find-one-bench
! find-all
{ small-doc medium-doc large-doc }
{ { } { index } } run-find-all-bench
! find-range
{ small-doc medium-doc large-doc }
{ { } { index } } run-find-range-bench
] with-db ;
MAIN: run-benchmarks

View File

@ -1,7 +1,7 @@
USING: accessors assocs bson.reader bson.writer byte-arrays
byte-vectors combinators formatting fry io io.binary io.encodings.private
io.encodings.binary io.encodings.string io.encodings.utf8 io.files
kernel locals math mongodb.msg namespaces sequences uuid ;
io.encodings.binary io.encodings.string io.encodings.utf8 io.encodings.utf8.private io.files
kernel locals math mongodb.msg namespaces sequences uuid bson.writer.private ;
IN: alien.c-types
@ -38,12 +38,6 @@ SYMBOL: msg-bytes-read
: change-bytes-read ( integer -- )
bytes-read> [ 0 ] unless* + >bytes-read ; inline
: write-byte ( byte -- ) 1 >le write ; inline
: write-int32 ( int -- ) 4 >le write ; inline
: write-double ( real -- ) double>bits 8 >le write ; inline
: write-cstring ( string -- ) output-stream get utf8 encoder-write 0 write-byte ; inline
: write-longlong ( object -- ) 8 >le write ; inline
: read-int32 ( -- int32 ) 4 [ read le> ] [ change-bytes-read ] bi ; inline
: read-longlong ( -- longlong ) 8 [ read le> ] [ change-bytes-read ] bi ; inline
: read-byte-raw ( -- byte-raw ) 1 [ read le> ] [ change-bytes-read ] bi ; inline
@ -156,7 +150,7 @@ USE: tools.walker
: (write-message) ( message quot -- )
'[ [ [ _ write-header ] dip _ call ] with-length-prefix ] with-buffer
! [ dump-to-file ] keep
[ dump-to-file ] keep
write flush ; inline
: build-query-object ( query -- selector )