ssbc / bipf

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

Simplify object key check, improving performance #12

Closed Barbarrosa closed 3 years ago

Barbarrosa commented 3 years ago

JavaScript only allows strings and symbols for object keys, and this lib doesn't support symbols. That leaves only strings, so we can assume that all encoded keys are strings and trigger a failure if they aren't strings. We can also skip all additional type checks.

This change measurably improved performance in my tests.

arj03 commented 3 years ago

I was also double checking specs and adding a test({1: true}) just to be sure that it worked as before. I also put it into some of our benchmark to see and as expected it didn't really change because we rarely decode a whole object. Anyway this is a nice change.