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

Avoid duplicated generation of APISpecification objects #3940

Conversation

mame
Copy link
Contributor

@mame mame commented Sep 11, 2020

Description:

What was the end-user or developer problem that led to this PR?

gem install aws-sdk is painfully slow

What is your fix for the problem, implemented in this PR?

As far as I could see, Gem::Resolver::APISpecification objects are
supposed to be immutable. If my guessing is correct, then we can cache
and reuse its instances for performance.
At least, rake passes on my machine.

Before this change:

$ time ruby -I lib bin/gem install --no-doc aws-sdk
Successfully installed aws-sdk-3.0.1
1 gem installed
real    0m37.104s
user    0m36.952s
sys     0m0.333s

After this change:

$ time ruby -I lib bin/gem install --no-doc aws-sdk
Successfully installed aws-sdk-3.0.1
1 gem installed
real    0m23.905s
user    0m23.740s
sys     0m0.365s

Tasks:

  • Describe the problem / feature
  • Write tests
  • Write code to solve the problem
  • Get code review from coworkers / friends

I will abide by the code of conduct.

As far as I could see, `Gem::Resolver::APISpecification` objects are
supposed to be immutable.  If my guessing is correct, then we can cache
and reuse its instances for performance.
At least, `rake` passes on my machine.

Before this change:

```
$ time ruby -I lib bin/gem install --no-doc aws-sdk
Successfully installed aws-sdk-3.0.1
1 gem installed
real    0m37.104s
user    0m36.952s
sys     0m0.333s
```

After this change:

```
$ time ruby -I lib bin/gem install --no-doc aws-sdk
Successfully installed aws-sdk-3.0.1
1 gem installed
real    0m23.905s
user    0m23.740s
sys     0m0.365s
```
@hsbt hsbt added this to the 3.2.0 milestone Sep 11, 2020
@hsbt hsbt merged commit 7c0a0dd into rubygems:master Sep 11, 2020
@hsbt
Copy link
Member

hsbt commented Sep 11, 2020

Thanks!

hsbt added a commit that referenced this pull request Sep 23, 2020
…specification-objects

Avoid duplicated generation of APISpecification objects
##
# We assume that all instances of this class are immutable;
# so avoid duplicated generation for performance.
@@cache = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Class variables are pretty inefficient, I think on all Ruby implementations.
Should we use a constant or @ivar on the class instead here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants