[ruby-core:67664] [ruby-trunk - Misc #10754] [Open] Tiny optimisation of Set#include?

1 view
Skip to first unread message

isma...@gmail.com

unread,
Jan 17, 2015, 8:29:19 PM1/17/15
to ruby...@ruby-lang.org
Issue #10754 has been reported by Ismael Abreu.

----------------------------------------
Misc #10754: Tiny optimisation of Set#include?
https://bugs.ruby-lang.org/issues/10754

* Author: Ismael Abreu
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Hi!

I'm not sure if this a relevant optimisation but here it goes. A simple way to improve Set#include?
I don't think there should be any side effects with this change.

Here are some dummy benchmarks https://gist.github.com/ismaelga/68bb3ea51b4742f65699
They are not consistent, but that should be because of garbage collection or something. Right?

I've also sent a Pull Request: https://github.com/ruby/ruby/pull/810

---Files--------------------------------
patch.diff (544 Bytes)


--
https://bugs.ruby-lang.org/

Eric Wong

unread,
Jan 17, 2015, 8:51:42 PM1/17/15
to Ruby developers
This speedup probably happens because Hash#[] has an optimized dispatch
VM instruction (opt_aref in insns.def) while Hash#include? does not.

Seems like an OK change to make, I'll commit in a few days unless others
raise objections.

normal...@yhbt.net

unread,
Jan 17, 2015, 8:59:17 PM1/17/15
to ruby...@ruby-lang.org
Issue #10754 has been updated by Eric Wong.
----------------------------------------
Misc #10754: Tiny optimisation of Set#include?
https://bugs.ruby-lang.org/issues/10754#change-51082

isma...@gmail.com

unread,
Jan 20, 2015, 5:51:29 PM1/20/15
to ruby...@ruby-lang.org
Issue #10754 has been updated by Ismael Abreu.


With the benchmarks I've run I noticed that ~~sometimes~~ rarely, the old include? was faster.
Do you have any idea why is that? The only cause I can think of is the GC.

----------------------------------------
Misc #10754: Tiny optimisation of Set#include?
https://bugs.ruby-lang.org/issues/10754#change-51141

Eric Wong

unread,
Jan 23, 2015, 2:58:04 PM1/23/15
to Ruby developers
I didn't notice the old code being faster, and I don't see your
benchmark triggering GC. Perhaps it is related to memory size
(swapping or CPU cache misses) or power management
(CPU clock frequency adjustment, "turbo boost", etc...)
Modern hardware is tricky to benchmark :/

normal...@yhbt.net

unread,
Jan 23, 2015, 2:58:42 PM1/23/15
to ruby...@ruby-lang.org
Issue #10754 has been updated by Eric Wong.
----------------------------------------
Misc #10754: Tiny optimisation of Set#include?
https://bugs.ruby-lang.org/issues/10754#change-51193

isma...@gmail.com

unread,
Feb 10, 2015, 7:50:22 PM2/10/15
to ruby...@ruby-lang.org
Issue #10754 has been updated by Ismael Abreu.


Any update on this?

----------------------------------------
Misc #10754: Tiny optimisation of Set#include?
https://bugs.ruby-lang.org/issues/10754#change-51470

Eric Wong

unread,
Feb 11, 2015, 2:05:43 PM2/11/15
to Ruby developers
Thanks for the reminder, I got distracted with other stuff :x
Committed r49568

isma...@gmail.com

unread,
Feb 12, 2015, 12:48:41 PM2/12/15
to ruby...@ruby-lang.org
Issue #10754 has been updated by Ismael Abreu.


Awesome! :)

Shouldn't this issue be closed also?

----------------------------------------
Misc #10754: Tiny optimisation of Set#include?
https://bugs.ruby-lang.org/issues/10754#change-51473

ruby...@marc-andre.ca

unread,
Feb 12, 2015, 5:18:33 PM2/12/15
to ruby...@ruby-lang.org
Issue #10754 has been updated by Marc-Andre Lafortune.

Status changed from Open to Closed

----------------------------------------
Misc #10754: Tiny optimisation of Set#include?
https://bugs.ruby-lang.org/issues/10754#change-51476

* Author: Ismael Abreu
* Status: Closed
Reply all
Reply to author
Forward
0 new messages