Skip to content

Adjust the API_REQUEST_LIMIT to make less network roundtrip#9071

Merged
hsbt merged 1 commit intoruby:masterfrom
Edouard-chin:ec-api-request-limit
Nov 13, 2025
Merged

Adjust the API_REQUEST_LIMIT to make less network roundtrip#9071
hsbt merged 1 commit intoruby:masterfrom
Edouard-chin:ec-api-request-limit

Conversation

@Edouard-chin
Copy link
Contributor

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

Getting a list of gems 50 per 50 is too slow and seems arbitrarily low.

This limit is used when Bundler fallback to getting a dependency list from a server /dependencies?gem= endpoint. Bundler uses this API endpoint fallback when a server doesn't expose the compact index API. This is not used for Rubygems.org, only private servers.

This limit is then divided by the number of dependency to get and the result is the number of request we'll be doing. The bottleneck on the client is the network roundtrip. On the server, getting the info of 50 or 100 gems is a bit more expensive but this operation is heavily cached.

This is an example of Rubygems.org implementation at the time the dependencies API wasn't deprecated https://github.com/rubygems/rubygems.org/blob/5a3a3ec02acc3a4e3aba077953a393ad20a06842/app/models/gem_dependent.rb#L15

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

50 gems to query seems arbitrary low. By doubling this number, we make twice as less API requests which ultimately can shove up to two seconds on application relying on a large number of gems.

Worth noting that the limit used to be 100 but got changed in e745f8d for a reason I ignore.

Make sure the following tasks are checked

- ### Problem

  This limit is used when Bundler fallback to getting a dependency
  list from a server `/dependencies?gem=` endpoint. Bundler uses
  this API endpoint fallback when a server doesn't expose the compact
  index API.
  This is not used for Rubygems.org, only private servers.

  This limit is then divided by the number of dependency to get
  and the result is the number of request we'll be doing.
  The bottleneck on the client is the network roundtrip. On the
  server, getting the info of 50 or 100 gems is a bit more expensive
  but this operation is heavily cached.

  This is an example of Rubygems.org implementation at the time the
  dependencies API wasn't deprecated
  https://github.com/rubygems/rubygems.org/blob/5a3a3ec02acc3a4e3aba077953a393ad20a06842/app/models/gem_dependent.rb#L15

  ### Context

  This limit used to be 100 a while ago but got changed
  to 50 in ruby@e745f8d
  I don't know why.

  ### Solution

  50 gems to query seems arbitrary low. By doubling this number, we
  make twice as less API requests which ultimately can shove up to two
  seconds on application relying on a large number of gems.
@hsbt
Copy link
Member

hsbt commented Nov 13, 2025

That's reasonable. We can revert this if we faced some problem.

@hsbt hsbt merged commit da30ef9 into ruby:master Nov 13, 2025
76 checks passed
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.

2 participants