The code is at https://github.com/fiatjaf/nostr-json-benchmarks

(as you can see, the "leaner" codec is much faster than anything else when running on Go.)

Reply to this note

Please Login to reply.

Discussion

The is code does not seem optimal.

Avoid using ‘data.buffer.slice()’ as it allocates memory and creates a copy.

Instead use ‘new DataView(data.buffer, byteOffset, byteLength)’ to reference the same buffer.

The javascript code does not seem optimal.

Avoid using ‘data.buffer.slice()’ as it allocates memory and creates a copy.

Have you tried using ‘new DataView(data.buffer, byteOffset, byteLength)’ to reference the same buffer?

If you need more performance, you may also use ‘new Uint8Array(data.buffer, byteOffset, length)’ which is common practice.

No, I did not try. I don't understand why can't we just have a simple byte array and instead have all these weird types. Please send a pull request.

OK, I did what you suggested and some other small optimizations. I wasn't expecting .slice() to do a copy. Now the performance is much better, but still more than 2x slower than JSON.parse and NSON.

Sorry was too busy this week to make a PR in time. 😊🙏🏼