hyperifyio / statelessdb

StatelessDB is a cloud database server that processes encrypted client-side data without storing state, enabling secure and scalable computations.
Other
0 stars 0 forks source link

TASK Experimental new encoding z3b #20

Closed thejhh closed 1 month ago

thejhh commented 1 month ago

New binary to text encoding which tries to be fast and dense, using rotating character maps.

Warning! It is still slower than and worse than base64 for random data.

Hello World (11 bytes)

RandomData: 256 bytes

z3b (375 bytes):

x W$j!P4~`;*4NeJ k ;-LE r_@oKK: EB;,W-k$w>_l-Y% dA r Z_0S9$O1 *_*`Z[-: ;=ASKl-wk]!Y4_p,tg_s~B-~._6_e lQ!q7_o(e_(`.<-)ZP!:# K &8-u9`i!B.,@4!/$K[W]S (!S/!&EJ-4o a$TgZ$?d:2z% t_4_7cL 9/`+xe>_i ez )?-+ bH`nm x!5Is!>Rh_(-f7 ,_b+o$Z Tn0 Y`@: V:q$0 >c&_L6$an )4_w ?U-Px G(>!Ta_gM qN qcU_OQ /!a:i ?_5 PSt|50y Z$j/ D_2-+H;H 48 %_tnA0}Rr`9e_{8`ued <[-MK-d_=t$.wB_xn`#( WE_Xu-P7_FNJ_Q v

base64 (344 bytes):

nMxsK/43Dyltp1rFRWZP30TJYmI2ZWA8DJfN8FHPjAa4VtmWG5o3gigPH6+0NjxCVpF5yuXNqp0czhnYqd79XP4hMcHDgNs+zQ6xBiRJFJJsRgViAjHiRcpJIR9DKyV2mI2Zgg6KJQJldDXSnnizklK4ORTwAdwcLaNmMhAd6LFBsLHqDVoPpWDIx+0wcuVXj8gOwjIWvBHSonbIIp1DPZpL2xtRnwODLa7RDinlQ3yK72kXTpOxqWjdfdi9pISOFaI9uFouipHm+Dkk8aK7GE8gCm88byUzAtzRVRv3ldlCwe042aemPaV/eK1Q5xvvSufRAQmNXqrdcS1jgXeO4w==

See https://github.com/hyperifyio/statelessdb/tree/dev/pkg/encodings/z3b

Benchmark

So, it's still really slow. No reason to optimize until it works better than base64.

z3b

BenchmarkEncodeZ3b_Small-12             1194        987417 ns/op
BenchmarkDecodeZ3b_Small-12          1829547           587.3 ns/op
BenchmarkEncodeZ3b_Medium-12              48      23496623 ns/op
BenchmarkDecodeZ3b_Medium-12          357049          3306 ns/op
BenchmarkEncodeZ3b_Large-12                1    18447076750 ns/op
BenchmarkDecodeZ3b_Large-12              196       6086775 ns/op

base64

BenchmarkEncodeBase64_Small-12      21568929            55.53 ns/op
BenchmarkDecodeBase64_Small-12      27360925            43.54 ns/op
BenchmarkEncodeBase64_Medium-12      1243725           924.2 ns/op
BenchmarkDecodeBase64_Medium-12      1748258           694.3 ns/op
BenchmarkEncodeBase64_Large-12          1405        731478 ns/op
BenchmarkDecodeBase64_Large-12          2095        549353 ns/op
thejhh commented 1 month ago

For now, we'll keep using base64.