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.59k stars 156 forks source link

optimize route building when there's query params. #1854

Closed jwoertink closed 6 months ago

jwoertink commented 6 months ago

Purpose

Fixes #1831

Description

Crystal 1.10 added a method overload for HTTP::Params.encode that takes an IO. This lets us use a single IO to build a route when there's query params.

There doesn't seem to really be a difference when there's no query params involved:

# SomeAction.with(id: 1).path
old   1.11k (901.42µs) (± 0.13%)  2.91MB/op        fastest
new   1.10k (906.13µs) (± 0.20%)  2.91MB/op   1.01× slower

But when you use query params, it helps

# SomeAction.with(id: 1, page: 1, per_page: 10).path
old 459.21  (  2.18ms) (± 1.57%)  6.87MB/op   1.30× slower
new 598.36  (  1.67ms) (± 1.12%)  4.27MB/op        fastest

Using a Crystal version below 1.10.0 will show a deprecation warning

[Deprecated] Please update your Crystal version "1.9.2". Using Lucky with a version below 1.10.0 is deprecated.

Checklist