-
Notifications
You must be signed in to change notification settings - Fork 8
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
Speed up #69
Conversation
private | ||
|
||
def now | ||
@now ||= Time.now |
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.
Why aren't we just setting this on the initialize?
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.
Same answer - if you never get a on: date
then we don't need to create this object.
lib/smart_todo/events.rb
Outdated
def rubygems_client | ||
@rubygems_client ||= Net::HTTP.new("rubygems.org", Net::HTTP.https_default_port).tap do |client| | ||
client.use_ssl = true | ||
end | ||
end | ||
|
||
def github_client | ||
@github_client ||= Net::HTTP.new("api.github.com", Net::HTTP.https_default_port).tap do |client| | ||
client.use_ssl = true | ||
end | ||
end | ||
|
||
def installed_ruby_version | ||
@installed_ruby_version ||= Gem::Version.new(RUBY_VERSION) |
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.
Why aren't we setting those in the initialize?
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 lazily setting these up because if you don't find any todos that have a gem version, there's no need to instantiate these objects. Basically it mirrors the previous behavior of lazily creating objects based on the todos you find.
lib/smart_todo/events/date.rb
Outdated
# An event that check if the passed date is passed | ||
class Date | ||
class << self | ||
# @param on_date [String] a string parsable by Time.parse | ||
# @return [String, false] | ||
def met?(on_date) | ||
if Time.now >= Time.parse(on_date) | ||
def met?(on_date, now = Time.now) |
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.
Do we even use this method without the second argument?
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, I just wasn't sure how much you wanted to break the existing APIs. Happy to make this required if you're prefer.
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.
It is fine to break API, all those classes are private API.
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.
Nice, in this case I've inlined the classes.
lib/smart_todo/events/gem_bump.rb
Outdated
@@ -17,16 +17,17 @@ class GemBump | |||
# | |||
# @example Expecting a version in the 5.x.x series | |||
# GemBump.new('rails', ['> 5.2', '< 6']) | |||
def initialize(gem_name, requirements) | |||
def initialize(gem_name, requirements, spec_set = Bundler.load.specs) |
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.
Do we use this class without the last argument?
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.
Nope, removed the class wholesale.
lib/smart_todo/events/gem_release.rb
Outdated
@@ -18,9 +18,10 @@ class GemRelease | |||
# | |||
# @example Expecting a version in the 5.x.x series | |||
# GemRelease.new('rails', ['> 5.2', '< 6']) | |||
def initialize(gem_name, requirements) | |||
def initialize(gem_name, requirements, client = nil) |
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.
Same here.
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.
Same here.
lib/smart_todo/events/issue_close.rb
Outdated
@@ -22,11 +22,12 @@ class IssueClose | |||
# @param organization [String] | |||
# @param repo [String] | |||
# @param pr_number [String, Integer] | |||
def initialize(organization, repo, pr_number, type:) | |||
def initialize(organization, repo, pr_number, client = nil, type:) |
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.
Same here
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.
Same here.
def initialize(requirements) | ||
attr_reader :installed_ruby_version | ||
|
||
def initialize(requirements, installed_ruby_version = Gem::Version.new(RUBY_VERSION)) |
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.
Same here
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.
Same here.
Just one sec - I released the new version of Prism so I'll make it point to rubygems.org |
@rafaelfranca this is good to go now. Should I merge? |
Yes. |
👋 Hi! I heard this could benefit from some improved performance, and also that it used ripper. I'm on a mission to remove ripper from everywhere. So, I took a look. I did a couple of things to improve performance, namely:
Events
from a module to a class. Previously, every event on every todo lined up to a method call to theEvents
module. That module would then instantiate whatever data it needed to do its job. But none of this data could be shared between todos. So it was discarded when the method call returned. Now instead we cache the data we want to keep around (like rubygems or github clients).There are still quite a few improvements I think could be put in place, but this seemed like a good place to stop. Those would be:
Overall, with these improvements in place, the time to parse Shopify's monolith on my computer went from
1:26.26
to22.789
:A couple of things to note:
Sorry about the size of this PR. I saw a bunch of stuff so I just kept going. Happy to trim this back to individual small commits if you'd prefer. I just figured I'd get this in front of eyes now and then we can reevaluate the scope of it.