Skip to content

marshal_dump is data is 8 times larger than necessary #25

@eproxus

Description

@eproxus

When using marshal_dump the bitmap is converted to some format which is 8 times larger than it has to be. Consider the following:

[307] pry(main)> filter
=> #<BloomFilter::Native:0x007f92e86daa10
 @bf=
  100110011000100001001101001001011010010001101000000001011010011000100
100100010010110110000011001100001111000100110010000010000000010001000
000010011101110000100000000010100000111000010000000101001011100110001
000100101101001100010100001100001000000001101101000111010101010001000
100111000010011000111000010000100000000011100000010000000010000000000
000010111010001010010001100111101110000011011000011000000100100000010
000110001000101000110010100000011011101010101001000000010110110001000
111100110011000010000100000000100000000101001010101000111000000000001
100000010011000001111001000000010100100000010001000100001000000001000
010100110001000000011010000011001010001000011000001101000100000111000
110010000000001110000000000011000110110001000000001000010100101000000
11110001001101100101100000001000100100101,
 @opts={:size=>800, :hashes=>6, :seed=>1373303094, :bucket=>4, :raise=>true}>
[308] pry(main)> filter.marshal_dump
=> [{:size=>800, :hashes=>6, :seed=>1373303094, :bucket=>4, :raise=>true},
 "\x01\x00\x00\x01\x01\x00\x00\x02\x02\x00\x00\x00\x02\x00\x00\x00\x00\x01\x00\x00\
x01\x01\x00\x01\x00\x00\x01\x00\x00\x01\x00\x01\x02\x00\x01\x00\x00\x01\x00\x00\x0
0\x01\x01\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01\x01\x00\x01\x00\x00\
x01\x01\x00\x00\x00\x01\x00\x00\x01\x00\x00\x01\x00\x00\x00\x02\x00\x00\x01\x00\x0
1\x01\x00\x01\x01\x00\x00\x00\x00\x00\x01\x01\x00\x00\x01\x01\x00\x00\x00\x00\x01\
x01\x01\x01\x00\x00\x00\x01\x00\x00\x02\x01\x00\x00\x01\x00\x00\x00\x00\x00\x01\x0
0\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\
x00\x00\x01\x01\x01\x00\x02\x01\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x0
0\x00\x00\x01\x00\x02\x00\x00\x00\x00\x00\x01\x01\x02\x00\x00\x00\x00\x01\x00\x00\
x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x00\x02\x02\x01\x00\x00\x01\x01\x00\x0
0\x00\x02\x00\x00\x00\x01\x00\x00\x01\x00\x01\x01\x00\x01\x00\x00\x01\x01\x00\x00\
x00\x01\x00\x01\x00\x00\x00\x00\x01\x02\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x0
0\x00\x00\x01\x01\x00\x02\x01\x00\x01\x00\x00\x00\x01\x01\x01\x00\x01\x00\x01\x00\
x01\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x01\x01\x01\x00\x00\x00\x00\x0
1\x00\x00\x02\x01\x00\x00\x00\x01\x02\x01\x00\x00\x00\x00\x02\x00\x00\x00\x00\x01\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x01\x01\x00\x00\x00\x00\x00\x00\x01\x00\x0
0\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x02\x00\x02\x01\x01\x00\x01\x00\x00\x00\x01\x00\x01\x00\x00\x01\x00\x00\x00\x0
2\x01\x00\x00\x01\x01\x01\x01\x00\x01\x01\x02\x00\x00\x00\x00\x00\x01\x01\x00\x01\
x01\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x01\x00\x00\x01\x00\x00\x00\x0
0\x00\x00\x01\x00\x00\x00\x00\x01\x01\x00\x00\x00\x02\x00\x00\x00\x01\x00\x01\x00\
x00\x00\x01\x01\x00\x00\x01\x00\x02\x00\x00\x00\x00\x00\x00\x02\x01\x00\x01\x01\x0
1\x00\x01\x00\x01\x00\x01\x00\x01\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x01\x00\
x01\x01\x00\x01\x01\x00\x00\x00\x01\x00\x00\x00\x01\x01\x01\x01\x00\x00\x01\x01\x0
0\x00\x01\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\
x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01\x00\x00\x01\x00\x01\x00\x01\x0
0\x01\x00\x00\x00\x01\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x01\
x00\x00\x00\x00\x00\x00\x01\x00\x00\x01\x02\x00\x00\x00\x00\x00\x01\x01\x01\x01\x0
0\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\
x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x0
0\x00\x00\x02\x00\x00\x00\x00\x01\x00\x01\x00\x00\x01\x01\x00\x00\x00\x01\x00\x00\
x00\x00\x00\x00\x00\x01\x01\x00\x01\x00\x00\x00\x00\x00\x01\x01\x00\x00\x01\x00\x0
1\x00\x00\x00\x02\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x01\x01\x00\x01\x00\
x00\x00\x01\x00\x00\x00\x00\x00\x01\x01\x01\x00\x00\x00\x01\x01\x00\x00\x01\x00\x0
0\x00\x00\x00\x00\x00\x00\x00\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x02\x01\x00\x00\x00\x01\x01\x00\x01\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x0
0\x00\x00\x01\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x00\x01\x00\x00\x00\x00\x00\
x00\x01\x02\x01\x01\x00\x00\x00\x01\x00\x00\x02\x01\x00\x01\x01\x00\x00\x01\x00\x0
1\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x01\x00\x00\x01\x00\
x02"]
[309] pry(main)> [filter.bf.to_s].pack("b*")
=> "\x99\x11\xB2\xA4%\x16\xA0e$\x916\x98\xE1\x91\t\x02D@\xEE\x10@\xC1!\xA0tF\xA4e
\x14\x86\x00[\\\x15\x91C\xC6!\x04p 
@\x00\xA0\x8B\x12\xF3\x0E6\f$\x10F\x14S`W%\xA0\x8Dxf\b\x01\x02\x94*\x0E\x80\x81
\f\x9E\x80\x12\x88\b\x01B\x19\x01\v\xA6\b\x83EpL\x00\a\xC0\xD8\b\x10J\x81G6\r\x88\
xA4"
[310] pry(main)> _.unpack("b*")
=> 
["10011001100010000100110100100101101001000110100000000101101001100010
010010001001011011000001100110000111100010011001000001000000001000100
000001001110111000010000000001010000011100001000000010100101110011000
100010010110100110001010000110000100000000110110100011101010101000100
010011100001001100011100001000010000000001110000001000000001000000000
000001011101000101001000110011110111000001101100001100000010010000001
000011000100010100011001010000001101110101010100100000001011011000100
011110011001100001000010000000010000000010100101010100011100000000000
110000001001100000111100100000001010010000001000100010000100000000100
001010011000100000001101000001100101000100001100000110100010000011100
011001000000000111000000000001100011011000100000000100001010010100000
011110001001101100101100000001000100100101"]

The dumped format seems to be limited to ~6 values only as individual characters, whereas the most efficient encoding is a binary string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions