Skip to content

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

Merged
jwoertink merged 3 commits intomainfrom
issues/1831
Mar 30, 2024
Merged

optimize route building when there's query params.#1854
jwoertink merged 3 commits intomainfrom
issues/1831

Conversation

@jwoertink
Copy link
Copy Markdown
Member

@jwoertink jwoertink commented Mar 24, 2024

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

  • - An issue already exists detailing the issue/or feature request that this PR fixes
  • - All specs are formatted with crystal tool format spec src
  • - Inline documentation has been added and/or updated
  • - Lucky builds on docker with ./script/setup
  • - All builds and specs pass on docker with ./script/test

Comment thread src/lucky/routable.cr
@jwoertink jwoertink merged commit ca4ee3e into main Mar 30, 2024
@jwoertink jwoertink deleted the issues/1831 branch March 30, 2024 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize this section of building a path

3 participants