Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8818 (closed enhancement: fixed)

Opened 1 year ago

Last modified 11 months ago

[PATCH] Disable Sym#to_proc for ruby 1.9

Reported by: lifofifo Assigned to: bitsweat
Priority: normal Milestone: 1.x
Component: ActiveSupport Version: edge
Severity: normal Keywords:
Cc: tarmo

Description

With regards to 8812, I'm submitting a new patch using suggestion made by Ara Howard at my blog.

This patch removes rarely used functionality with enumerator(&:symtoproc), and by doing so, improves performance by almost 7 times in my case (could differ for different platforms/processors etc).

Also attaching scripts for performance benchmarking with old and new approaches.

Thanks.

Attachments

sym_to_proc_performance_improvement.patch (0.8 kB) - added by lifofifo on 06/30/07 13:02:46.
Improve enumerator(&:sym) performance
perform.rb (1.2 kB) - added by lifofifo on 06/30/07 13:05:12.
Performance test for rails
ruby_perform.rb (0.9 kB) - added by lifofifo on 06/30/07 13:05:33.
Performance test for pure ruby code
symtoproc.rb (1.5 kB) - added by lifofifo on 07/06/07 12:21:31.
Performance comparision with Ruby 1.9
no_symtoproc_for_ruby_1_9.patch (454 bytes) - added by lifofifo on 07/06/07 12:22:06.
Don't define to_proc for ruby 1.9

Change History

06/30/07 13:02:46 changed by lifofifo

  • attachment sym_to_proc_performance_improvement.patch added.

Improve enumerator(&:sym) performance

06/30/07 13:05:12 changed by lifofifo

  • attachment perform.rb added.

Performance test for rails

06/30/07 13:05:33 changed by lifofifo

  • attachment ruby_perform.rb added.

Performance test for pure ruby code

06/30/07 20:49:43 changed by eventualbuddha

I don't believe I use the form of Symbol#to_proc that allows passing arguments, but given that some people might, I'd suggest deprecating that way first before this patch is included.

07/01/07 06:05:49 changed by tarmo

  • cc set to tarmo.

07/05/07 07:41:52 changed by kamal

+1

07/06/07 10:51:26 changed by murphy

-1

This would break functionality as added by [4455]. It seems like premature optimization to me. If you're running into a bottleneck, write a proc yourself - or use the good ol' blocks ;)

Also, Ruby 1.9 has it build right in (coming this Xmas), with best performance, and it works exactly like the current Symbol#to_proc. We shouldn't break compatibility.

07/06/07 10:55:37 changed by lifofifo

1.9 is a long way. Plus, the patch doesn't really break any existing tests.

07/06/07 11:22:27 changed by murphy

Perhaps such a test should be added.

  assert_equal(6, [1, 2, 3].inject(&:+))

07/06/07 12:21:31 changed by lifofifo

  • attachment symtoproc.rb added.

Performance comparision with Ruby 1.9

07/06/07 12:22:06 changed by lifofifo

  • attachment no_symtoproc_for_ruby_1_9.patch added.

Don't define to_proc for ruby 1.9

07/06/07 12:23:03 changed by lifofifo

I've added performance comparision for ruby 1.9. And also a patch for defining to_proc only if ruby version is < 1.9

07/06/07 12:58:03 changed by murphy

Same results here. Interesting, indeed. I've asked ruby-core ML if something can be done about this. It seems block calls with only one argument are heavily optimized; maybe we can do some magic to Symbol#to_proc.

07/27/07 00:24:43 changed by lifofifo

  • priority changed from high to normal.

09/27/07 10:46:20 changed by lifofifo

  • owner changed from core to bitsweat.

09/27/07 10:47:51 changed by lifofifo

  • summary changed from [PATCH] enumerator(&:symtoproc) performance improvement to [PATCH] Disable Sym#to_proc for ruby 1.9.

09/27/07 16:46:30 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

11/15/07 04:15:00 changed by lawrence

  • status changed from closed to reopened.
  • resolution deleted.

Seems to me the no_symtoproc_for_ruby_1_9.patch didn't get into the changeset.

11/15/07 05:55:05 changed by BobSilva

unless :test.respond_to?(:to_proc)

11/15/07 09:39:16 changed by bitsweat

  • status changed from reopened to closed.
  • resolution set to fixed.