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

Make clients autoload #1351

Merged
merged 2 commits into from May 24, 2022
Merged

Make clients autoload #1351

merged 2 commits into from May 24, 2022

Conversation

gmcgibbon
Copy link
Contributor

Make clients autoload so that requiring the gem doesn't slow down boot time of apps that use this gem. In our app, it took about 400ms to load Octokit::Client on boot:

Screen Shot 2021-07-22 at 3 41 36 PM

You can test this on a simpler scale by wrapping the test suite require in a benchmark block like so:

# spec/helper.rb

require "benchmark"
ms = Benchmark.realtime do
  require 'octokit'
end * 1000
puts "took #{ms}ms to laod"

Pre patch this took around ~200ms and post patch about 110ms on my machine. Not quite 2x faster, but still worth autoloading I think. The autoload patched client also removes octokit from our app profiles, which means the require time is reduced significantly in both cases.

@tas50
Copy link

tas50 commented Aug 10, 2021

@gmcgibbon What are you using to visualize the load time there?

@gmcgibbon
Copy link
Contributor Author

@tas50 I'm using stackprof to measure and speedscope to visualize!

@@ -2,7 +2,6 @@
require 'octokit/warnable'
require 'octokit/arguments'
require 'octokit/repo_arguments'
require 'octokit/configurable'
require 'octokit/authentication'
require 'octokit/gist'
require 'octokit/rate_limit'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move these to autoloads in the Octokit module as well in case they are referenced before Client?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right... it depends on the API of the gem. It looks like they are all public API and you expect these modules to be pluggable by other client types.

I'll take a look at the modules that aren't under Client and see if it makes sense to autoload them. If they are trivial enough, we could consider just moving the require.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to autoload all constants nested in Octokit besides Configurable (because that's used immediately in the main module). It should be roughly the same performance diff that way.

Copy link

@jhawthorn jhawthorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

@gmcgibbon
Copy link
Contributor Author

@tarebyte this should be ready whenever you have a moment to review. 🙏

@gmcgibbon
Copy link
Contributor Author

Happy new year! I'd still like to see this merged when someone has a chance. ❤️

@gmcgibbon
Copy link
Contributor Author

@jhawthorn are you able to ping someone with merge access to look at this? It looks like this is still an issue.

@nickfloyd
Copy link
Contributor

@gmcgibbon we're needing to roll back this change in our next release. It turns out this had some side effects that we are going to need to think through and work around. see #1427

Apologies for the back and forth on this - the change you proposed here is a good one, we just need to introduce it in such a way that doesn't cause harm to other users.

@nickfloyd
Copy link
Contributor

Reverted in release v4.24.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants