hattipjs / hattip

Like Express, but for the future
MIT License
1.26k stars 15 forks source link

Add HatTip to Bun HTTP benchmark #114

Open redbar0n opened 9 months ago

redbar0n commented 9 months ago

Would be nice to see HatTip at https://github.com/SaltyAom/bun-http-framework-benchmark

Related issue: https://github.com/SaltyAom/bun-http-framework-benchmark/issues/58

cyco130 commented 8 months ago

Ugh, this is a fairly useless benchmark.

For example, Hono on Bun looks like it performs badly. But just go to src/bun/hono.ts and change the export to export default { ...app, host: '127.0.0.1' } (instead of export default app) for an instant 20% speed boost that puts it right up, near the top.

If you're curious, with the above trick, Hattip on Bun performs a bit better than Hono without the trick. If I change the URL parser from new URL to something manual with indexOf and the query parser to a simple regex-based one, it catches up with Hono with the trick. You can go even faster by using other tricks like creating the same "Hi" response once and using clone to duplicate it and creating the options objects once and reusing them. Using a Headers object also seems to be faster. I really don't see much point but I'm designing a new router in any case. I will submit it once it's done anyway.

Also, exercising the same code path repeatedly like in here will show very different performance characteristics compared to a more realistic load profile.

I'll try to find better tools for load testing.

redbar0n commented 6 months ago

Maybe it'd be an idea to add HatTip to the Web Frameworks Benchmark too.