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
3.x perf #506
3.x perf #506
Conversation
consistent strings
consistent strings
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
use default cache size for new caches
the cache size is the real deal here, i got CONSTANT cache misses, and even worse, sprockets limited the internal cache size to 1024 entries, so that was killing everything i get unbelievable good numbers now, too good to publish :) |
@@ -56,6 +56,7 @@ def parse_q_values(values) | |||
# | |||
# Returns Array of matched Strings from available Array or []. | |||
def find_q_matches(q_values, available, &matcher) | |||
return [] if available == [] |
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.
We're allocating an array everytime this if code is called. We can speed it up by using a pre-allocated constant
require 'benchmark/ips'
x = ""
EMPTY_ARRAY = [].freeze
Benchmark.ips do |x|
x.report("constant") { x if x == EMPTY_ARRAY }
x.report("literal ") { x if x == [] }
end
Gives us
Warming up --------------------------------------
constant 326.041k i/100ms
literal 306.879k i/100ms
Calculating -------------------------------------
constant 10.675M (± 7.9%) i/s - 53.145M in 5.011048s
literal 8.301M (± 7.7%) i/s - 41.429M in 5.022438s
Comparison:
constant: 10675185.0 i/s
literal : 8300648.6 i/s - 1.29x slower
@@ -35,6 +35,21 @@ def compress | |||
scheme + compressed_path | |||
end | |||
|
|||
def self.fast_compress(uri, root) | |||
if uri.include?('://'.freeze) |
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.
We don't need all the freeze calls. We're using the magic comment in the files:
# frozen_string_literal: true
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.
oh, right, missed that
Sorry for the delay here. I think i'm ready to start looking at merging some of this stuff. Can you split this up into individual patches? Don't convert double quotes to single, performance difference is negligible and it messes up the git blame. My personal preference is double quotes everywhere so when they're mixed and right next to each other it looks fine. for the
I'm not sure what risks there are by changing the cache default numbers. |
well, problem are different ruby implementations and platforms and so on, its faster for me, but slower for others, i dont mind throwing a_v_t_d in the bin or the other minor improvements. A lot of speed is gained by other means. Most important here is the regexp patch. |
Are you on opal? Do you know if it implemented compare by identity? https://github.com/rails/sprockets/pull/439/files |
oops, i missed your question, sorry. since 0.11 it has - Added |
numbers without cache adjustment
o_jit: measured from within opals javascript_include_tag
recompile meaning recompiling an opal .rb file with sprockets
first ojit is an large static asset
second o_jit is the dynamic one for recompile
patches beside the regexp patch are for compiling performance.
tests run with matz ruby 2.4.2
#503