Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small performance improvement when generating a route url. #1829

Merged
merged 1 commit into from
Sep 15, 2023

Conversation

jwoertink
Copy link
Member

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

  • - 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

@jkthorne
Copy link
Contributor

jkthorne commented Sep 6, 2023

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

@jwoertink
Copy link
Member Author

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

@jwoertink jwoertink merged commit 0bcc91f into main Sep 15, 2023
4 of 5 checks passed
@jwoertink jwoertink deleted the issues/1827 branch September 15, 2023 15:11
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.

None yet

2 participants