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
[x] - An issue already exists detailing the issue/or feature request that this PR fixes
[x] - All specs are formatted with crystal tool format spec src
[x] - Inline documentation has been added and/or updated
[x] - Lucky builds on docker with ./script/setup
[x] - All builds and specs pass on docker with ./script/test
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:This is from generating 10k URLs using
Users::Show.with(1).url
Checklist
crystal tool format spec src
./script/setup
./script/test