I have a 1.7MB object to send.
Doing this will cause a TTFB time of 330ms (that's ok) and a Content download time of 4s in Chrome.
router.get('/heavy', async function heavyRoute(ctx, next) {
const result = await collectHeavyData()
ctx.body = result // my 1.7MB object
console.log('less than 100ms and we are here')
})
The same logic written with .NET cause a TTFB time of 2s (that's ok, my bad) and a Content download time of 92ms.
The response are the same, the Koa route code execute in less than 100ms, but the client get the complete response really slowly.
Am I missing something?
The issue appear even on production mode.
try using streams or a more optimized JSON.stringify() module
Just as @jonathanong wrote, @greguz - use Streams since it is where Node.js shines and has the biggest advantage over other back-end technologies. Stream will basically divide your object/file into small chunks of data and send them one by one. It may sounds crazy but results are astonishing.
I am going to close this issue. Feel free to re-open if you still believe this to be an issue with Koa.
Most helpful comment
try using streams or a more optimized
JSON.stringify()module