-
Notifications
You must be signed in to change notification settings - Fork 27
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
Optimise Imgix::Path#to_url by not generating the escaped query string twice #103
Conversation
Output: ``` ❯ bundle exec ruby script/bench_to_url.rb Warming up -------------------------------------- Imgix::Path#to_url 1.683k i/100ms Calculating ------------------------------------- Imgix::Path#to_url 16.886k (± 0.6%) i/s - 85.833k in 5.083431s ```
Tests
Performance Improvements
ContributorsCommit-Lint commandsYou can trigger Commit-Lint actions by commenting on this PR:
|
Benchmark output: ``` ❯ bundle exec ruby script/bench_to_url.rb Warming up -------------------------------------- Imgix::Path#to_url 2.731k i/100ms Calculating ------------------------------------- Imgix::Path#to_url 27.278k (± 0.7%) i/s - 136.550k in 5.006213s ```
6b38dad
to
4d0891f
Compare
Hey there @stevehodgkiss thanks for the PR! I've pinged someone on our team with more extensive knowledge of this library than me to take a look at this, and hopefully we can get this merged in soon! |
@stevehodgkiss Nice! At a glance, I like this a lot. I'm currently working on performance improvements in our codebase and deferring computation until it's needed is a technique I use often (it often helps to de-duplicate computation). I will review this more thoroughly later today/tomorrow. Thanks for this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @stevehodgkiss, this seems like a straightforward boost to me 👍
Description
In profiling an application that renders a lot of Imgix images, I noticed a significant amount of time spent escaping the query string in
Imgix::Path#query
.To generate a URL,
Imgix::Path#query
is called twice - once for the URL to be rendered, and again to generate the signature.The change in this PR avoids generating the escaped query string twice, and almost doubles the performance of
to_url
on my machine.Before:
After: