Skip to content

* lib/timeout.rb: freeze a string message - #996

Closed
JuanitoFatas wants to merge 1 commit into
ruby:trunkfrom
JuanitoFatas:let-it-go
Closed

* lib/timeout.rb: freeze a string message#996
JuanitoFatas wants to merge 1 commit into
ruby:trunkfrom
JuanitoFatas:let-it-go

Conversation

@JuanitoFatas

Copy link
Copy Markdown
Member

Why: Saves ~ 1M string allocations on every request

From benchmarking one of my rails app, I found this line allocating

many string objects.

1050056 /Users/Juan/.rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:80

Before this patch

   2828765  activerecord-4.2.3
   2695930  ruby-2.2.2/lib
   1057453  activesupport-4.2.3

After this patch

allocated memory by gem
-----------------------------------
   2828765  activerecord-4.2.3
   1627551  ruby-2.2.2/lib
   1057213  activesupport-4.2.3

I use derailed_benchmarks gem to benchmark my Rails app, the exact command is

bundle exec derailed exec perf:objects

Why: Saves ~ 1M string allocations on every request

From benchmarking one of my rails app, I found this line allocating

many string objects.

1050056  /Users/Juan/.rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:80

Before this patch

   2828765  activerecord-4.2.3
   2695930  ruby-2.2.2/lib
   1057453  activesupport-4.2.3

After this patch

allocated memory by gem
-----------------------------------
   2828765  activerecord-4.2.3
   1627551  ruby-2.2.2/lib
   1057213  activesupport-4.2.3

I use derailed_benchmarks gem to benchmark my Rails app, the exact command is

bundle exec derailed exec perf:objects
@nobu nobu closed this in b0f2785 Aug 13, 2015
@JuanitoFatas
JuanitoFatas deleted the let-it-go branch August 13, 2015 15:38
@JuanitoFatas

Copy link
Copy Markdown
Member Author

Thanks! 🙇

nurse pushed a commit to nurse/ruby that referenced this pull request Sep 18, 2015
* lib/timeout.rb (Timeout#timeout): freeze a string message to
  reduce string allocations.  [Fix rubyGH-996]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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.

1 participant