ssbc / bipf

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

Optimize JS code with V8 tricks #24

Open staltz opened 2 years ago

staltz commented 2 years ago

Continuing from https://github.com/jerive/bipf-napi/issues/1#issuecomment-985868777

@jerive I noticed that in test/perf.js, sometimes seekKey(buffer, start, target) is called with buffer = 0 and that's what causes a deopt. We could do two things: (1) check why is buffer = 0 being passed to this function in the perf.js, and not pass that (invalid) arg, (2) put a if (Buffer.isBuffer(buffer)) check in the implementation, although this will likely impact performance a tiny bit.

jerive commented 2 years ago
at seekKey (/home/jerome/dev/bipf/index.js:235:11)
    at Array.eval (eval at createSeekPath (/home/jerome/dev/bipf/index.js:336:10), <anonymous>:6:11)
    at /home/jerome/dev/bipf/index.js:452:27
    at Object.<anonymous> (/home/jerome/dev/bipf/test/perf.js:166:3)

Something wrong with createCompareAt: the function produced is indeed not called the proper way in perf.js (with 4 args instead of 2, probably a confusion with bipf.compare)