Closed beautimode closed 4 years ago
JSON encoding as a performance penalty that is visible across all frameworks, here's one independent example:
JSON: https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=json&l=zik0sf-1r text: https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=plaintext&l=zik0sf-1r
One way we could improve this could be by writing a custom encoder that encodes directly to a buffer to be send to the network layer. But this would mean we would require users to not use JSON.stringify({...})
but something else like JSON.bufferify({...})
.
Currently JSON.stringify
should handle both native and js types.
Should I use JSON.stringify or is there better way?
Using JSON.stringify drops the performance about 40% compares to
ctx.response().end("hello world")
It's really often for a server to respond json data, but I can't find any hands-on API for the job. Is there a better way to do that?