ssbc / bipf

Binary json codec optimized for in-place access
MIT License
48 stars 9 forks source link

Improve seekKey2 #33

Closed arj03 closed 2 years ago

arj03 commented 2 years ago

I was looking at seekKey2 to see what it actually does. It seems to be a performance improvement compared to seekKey by taking in an encoded target. Similar to seekKey being faster on buffers directly. I improved the performance test a bit because the second time you run a function v8 has optimized it a bit. So the previous comparison was a bit unfair. Not super happy about the name, changing that would be a breaking change.

Anyway performance gains are real in real world tests as well. I ported over jitdb to use this function and my normal db2 performance test improved from roughly 10.5 seconds to 10 seconds.

arj03 commented 2 years ago
operation, ops/ms
BIPF.encode 1.3338668800853675
JSON.stringify 2.985965959988056
BIPF.decode 4.22654268808115
JSON.parse 5.747126436781609
JSON.parse(buffer) 5.497526113249038
JSON.stringify(JSON.parse()) 3.029385034837928
BIPF.seek(string) 322.5806451612903
BIPF.seek(buffer) 625
BIPF.seek2(encoded) 526.3157894736842
BIPF.seek2(encoded) second run 666.6666666666666
BIPF.seekCached(buffer) 1666.6666666666667
BIPF.seekPath(encoded) 555.5555555555555
BIPF.seekPath(compiled) 555.5555555555555
BIPF.compare() 285.7142857142857
BIPF.seek(uniqueMsg) 625
BIPF.seekCached(uniqueMsg) 1428.5714285714287
arj03 commented 2 years ago

666.666 :metal: