]> Cypherpunks repositories - gostls13.git/commit
suffixarray: improved serialization code
authorRobert Griesemer <gri@golang.org>
Tue, 20 Sep 2011 21:36:19 +0000 (14:36 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 20 Sep 2011 21:36:19 +0000 (14:36 -0700)
commit5ee7ef90cddf2d5b3fa7fd9092a86f47fc5d56ee
treeda9a1f5f9f3bada636ab3bd929e5153803242260
parent86e65bac5c9368fc807f8c0356fe5162fb68b09e
suffixarray: improved serialization code

Use gobs to serialize indexes instead of encoding/binary.

Even with gobs, serialize data in slices instead of
applying gob to the entire data structure at once,
to reduce the amount of extra buffer memory needed
inside gob.

7x faster Write/Read for new BenchmarkSaveRestore
compared to old code; possibly because encoding/binary
is more expensive for int32 slice elements (interface
call to get little/big endian encoding), while gob's
encoding is fixed (unconfirmed).

new (using gobs):
suffixarray.BenchmarkSaveRestore        1 2153604000 ns/op

old (using encoding/binary):
suffixarray.BenchmarkSaveRestore        1 15118322000 ns/op

The actual serialized data is slightly larger then using
the old code for very large indices because full 32bit indices
require 5bytes using gobs instead of 4bytes (encoding/binary)
in serialized form.

R=r
CC=golang-dev
https://golang.org/cl/5087041
src/pkg/index/suffixarray/suffixarray.go
src/pkg/index/suffixarray/suffixarray_test.go