From: Eric Wong <e@80x24.org> To: meta@public-inbox.org Subject: [PATCH 2/9] ds: cleanup Errno imports and favor constant comparisons Date: Mon, 10 Jun 2019 05:18:39 +0000 Message-ID: <20190610051846.26757-3-e@80x24.org> (raw) In-Reply-To: <20190610051846.26757-1-e@80x24.org> Stop importing unused constants, and favor integer comparisons of `$!' over `$!{EFOO}' hash lookups. Integer comparisons are slightly faster, even: Benchmark: timing 30 iterations of cmp_eq, cmp_ne, hash_hit, hash_miss... cmp_eq: 1 wallclock secs ( 1.61 usr + 0.00 sys = 1.61 CPU) @ 18.63/s (n=30) cmp_ne: 2 wallclock secs ( 1.57 usr + 0.00 sys = 1.57 CPU) @ 19.11/s (n=30) hash_hit: 4 wallclock secs ( 3.85 usr + 0.00 sys = 3.85 CPU) @ 7.79/s (n=30) hash_miss: 4 wallclock secs ( 3.74 usr + 0.00 sys = 3.74 CPU) @ 8.02/s (n=30) #!/usr/bin/perl -w use Benchmark qw(:all); use Errno qw(EAGAIN EINTR); my ($r, $w); pipe($r, $w) or die 'pipe'; require IO::Handle; $r->blocking(0); my $buf; my $n = 30000; timethese(30, { hash_hit => sub { sysread($r, $buf, 1); for (0..$n) { next if $!{EAGAIN}; die 'FAIL'; } } , 'cmp_eq' => sub { sysread($r, $buf, 1); for (0..$n) { next if $! == EAGAIN; die 'FAIL'; } }, hash_miss => sub { sysread($r, $buf, 1); for (0..$n) { die 'FAIL' if $!{EINTR}; } }, 'cmp_ne' => sub { sysread($r, $buf, 1); for (0..$n) { die 'FAIL' if $! == EINTR; } }, }); --- lib/PublicInbox/DS.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 172a9f52..39f1922f 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -33,8 +33,7 @@ use fields ('sock', # underlying socket 'event_watch', # bitmask of events the client is interested in (POLLIN,OUT,etc.) ); -use Errno qw(EINPROGRESS EWOULDBLOCK EISCONN ENOTSOCK - EPIPE EAGAIN EBADF ECONNRESET ENOPROTOOPT); +use Errno qw(EPIPE EAGAIN ECONNRESET EINVAL); use Carp qw(croak confess); use constant DebugLevel => 0; @@ -462,7 +461,7 @@ sub new { } retry: if (epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, $ev)) { - if ($!{EINVAL} && ($ev & $EPOLLEXCLUSIVE)) { + if ($! == EINVAL && ($ev & $EPOLLEXCLUSIVE)) { $EPOLLEXCLUSIVE = 0; # old kernel $ev = $self->{event_watch} = EPOLLIN|EPOLLERR|EPOLLHUP; goto retry; @@ -730,7 +729,7 @@ sub read { my $res = sysread($sock, $buf, $req_bytes, 0); DebugLevel >= 2 && $self->debugmsg("sysread = %d; \$! = %d", $res, $!); - if (! $res && $! != EWOULDBLOCK) { + if (! $res && $! != EAGAIN) { # catches 0=conn closed or undef=error DebugLevel >= 2 && $self->debugmsg("Fd \#%d read hit the end of the road.", $self->{fd}); return undef; -- EW
next prev parent reply other threads:[~2019-06-10 5:18 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-06-10 5:18 [PATCH 0/9] ds: Diet Socket Eric Wong 2019-06-10 5:18 ` [PATCH 1/9] ds: simplify write buffer accounting Eric Wong 2019-06-10 5:18 ` Eric Wong [this message] 2019-06-10 5:18 ` [PATCH 3/9] ds: reduce Errno imports and drop ->close reason Eric Wong 2019-06-10 5:18 ` [PATCH 4/9] ds: remove {fd} field Eric Wong 2019-06-10 5:18 ` [PATCH 5/9] ds: remove steal_socket method Eric Wong 2019-06-10 5:18 ` [PATCH 6/9] nntp: use sysread to append to existing buffer Eric Wong 2019-06-10 5:18 ` [PATCH 7/9] ds: remove read method, here, too Eric Wong 2019-06-10 5:18 ` [PATCH 8/9] ds: do not distinguish between POLLHUP and POLLERR Eric Wong 2019-06-10 5:18 ` [PATCH 9/9] ds: stop caring about event flags set by epoll/poll/kqueue Eric Wong
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://public-inbox.org/README * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190610051846.26757-3-e@80x24.org \ --to=e@80x24.org \ --cc=meta@public-inbox.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
user/dev discussion of public-inbox itself This inbox may be cloned and mirrored by anyone: git clone --mirror http://public-inbox.org/meta git clone --mirror http://czquwvybam4bgbro.onion/meta git clone --mirror http://hjrcffqmbrq6wope.onion/meta git clone --mirror http://ou63pmih66umazou.onion/meta # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V1 meta meta/ http://public-inbox.org/meta \ meta@public-inbox.org public-inbox-index meta Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta nntp://news.gmane.io/gmane.mail.public-inbox.general note: .onion URLs require Tor: https://www.torproject.org/ code repositories for the project(s) associated with this inbox: https://80x24.org/public-inbox.git AGPL code for this site: git clone https://public-inbox.org/public-inbox.git