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

Optimize Grape::Path -> Reduce Hash Allocation #2513

Merged
merged 6 commits into from
Nov 30, 2024

Conversation

ericproulx
Copy link
Contributor

This PR refactors the usage of Grape::Path and it comes with a lower Hash allocation. Most of the changes are in Grape::Path and the to_routes function in Grape::Endpoint

This is the result taken from the benchmark/compile_many_routes.rb

require 'memory_profiler'

class API < Grape::API
  prefix :api
  version 'v1', using: :path

  2000.times do |index|
    get "/test#{index}/" do
      'hello'
    end
  end
end

MemoryProfiler.report(allow_files: 'grape') do
  API.compile!
end.pretty_print
Screenshot 2024-11-26 at 20 34 00 Screenshot 2024-11-26 at 20 33 34

@ericproulx ericproulx marked this pull request as ready for review November 30, 2024 14:48
@dblock
Copy link
Member

dblock commented Nov 30, 2024

Alright thanks!

@dblock dblock merged commit 92573ea into ruby-grape:master Nov 30, 2024
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants