luckyframework / lucky

A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts.
https://luckyframework.org
MIT License
2.57k stars 156 forks source link

small performance improvement when generating a route url. #1829

Closed jwoertink closed 9 months ago

jwoertink commented 10 months ago

Purpose

Ref #1827

Description

Still investigating what can be done on #1827 for a bit more speed. I don't think we can match the performance of returning a raw string in an action, but little bits like this might help get it closer. This PR utilizes a method overload for encode_www_form that takes an IO to reduce the allocations. Here's a benchmark:

old 563.31  (  1.78ms) (± 0.65%)  7.17MB/op   1.54× slower
new 866.54  (  1.15ms) (± 0.95%)  3.37MB/op        fastest

This is from generating 10k URLs using Users::Show.with(1).url

Checklist

jkthorne commented 10 months ago

one of these days a 33% increase will seem like a giant leap forward

jwoertink commented 9 months ago

Looks like this patch makes a pretty big difference on apps under stress load.