Project

General

Profile

Actions

Bug #8208

closed

Raise cached exceptions for nonblocking IO to avoid allocation/stack-copying costs

Added by headius (Charles Nutter) about 11 years ago. Updated over 10 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
2.0.0
Backport:
[ruby-core:53922]

Description

Currently, all nonblocking IO APIs raise exceptions when the IO channel cannot perform the requested read or write without blocking. This adds a tremendous performance hit to nonblocking IO, since raising an exception requires both allocating the exception object and saving off the backtrace information from the call stack.

Two changes could reduce this cost:

  1. Don't provide a full backtrace for these exceptions, or only provide it in a debug or verbose modes. 99% of the rescuers of these exceptions don't ever use the backtrace, so it's wasted overhead.

  2. Always raise a cached exception. This completely avoids all allocation costs for nonblocking operations that fail.

JRuby does #1 in JRuby 1.7 series, but does not do #2. I will work on a patch for MRI to do both #1 and #2.

The benefit of this change would be that nonblocking IO has zero wasted overhead. The down side would be that the exceptions raised do not have a useful backtrace unless debug or verbose.

If we did this change, we would not have to introduce a separate API for nonblocking IO that doesn't raise exceptions.

Thoughts?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0