SASADA Koichi <ko1 / atdot.net> wrote:
> Clearing method caching cause the following 2 overheads:
> 
> (1) Clearing overhead
> (2) Cache misses because of clearing methods
> 
> Which is your purpose?

I used oprofile last year and think I was measuring CPU time, so (1)...

> For (1), I made an alternative patch:
>   http://www.atdot.net/sp/readonly/x8wjml

Awesome!  It gives roughly the same performance as my ephemeral class
patch in my measurement script below and less intrusive.

Thank you very much for your feedback.

> For (2), ephemeral class seems good.

Your patch for (1) improves (2), too.  However, I think cache miss
is already a huge problem because cache-clearing is called during GC.

"perf -e cache-misses" reported the same results (~910 for either patch
vs 1K on unpatched trunk) with a formatted version of the one-liner
Charles posted earlier:

---------------------- 8< ----------------------
require 'benchmark'
require 'socket'

def loop_eagain(sock)
  i = 0
  begin
    sock.read_nonblock(1)
  rescue Errno::EAGAIN
    return if i >= 10_000
    i += 1
    retry
  end
end

host = 'yhbt.net' # yhbt.net webmaster is OK with testing against it
10.times {
  sock = TCPSocket.new(host, 80)
  puts Benchmark.measure { loop_eagain(sock) }
}
-- 
Eric Wong