ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: headius@headius.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:72527] [Ruby trunk - Feature #11339] [PATCH] io.c: avoid kwarg parsing in C API
Date: Sun, 27 Dec 2015 22:49:10 +0000	[thread overview]
Message-ID: <redmine.journal-55791.20151227224909.c19dfc49056ebdeb@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11339.20150707215946@ruby-lang.org

Issue #11339 has been updated by Charles Nutter.


I don't usually jump in to grouse about CRuby changes, but this is really gross. We shouldn't be mucking up the core classes like this just to work around a missing optimization in the runtime.

I'd strongly recommend making a better rb_define_method system that allows you to pass keyword arguments directly to C code rather than having to make changes like this all over the place. Here's hoping that happens sooner rather than later and this change is only temporary.

We won't be making this change in JRuby, so our copy of socket.rb will diverge from MRI's. JRuby does not currently do allocation-free keyword arguments, but we will implement it soon for both Ruby targets *and* native targets.

----------------------------------------
Feature #11339: [PATCH] io.c: avoid kwarg parsing in C API
https://bugs.ruby-lang.org/issues/11339#change-55791

* Author: Eric Wong
* Status: Closed
* Priority: Normal
* Assignee: 
----------------------------------------
~~~
rb_scan_args and hash lookups for kwargs in the C API are clumsy and
slow.  Instead of improving the C API for performance, use Ruby
instead :)

Implement IO#read_nonblock and IO#write_nonblock in prelude.rb
to avoid argument parsing via rb_scan_args and hash lookups.

This speeds up IO#write_nonblock and IO#read_nonblock benchmarks
in both cases, including the original non-idiomatic case where
the `exception: false' hash is pre-allocated to avoid GC pressure.

Now, writing the kwargs in natural, idiomatic Ruby is fastest.
I've added the noex2 benchmark to show this.

target 0: a (ruby 2.3.0dev (2015-07-08 trunk 51190) [x86_64-linux]) at "a/ruby"
target 1: b (ruby 2.3.0dev (2015-07-08 nonblock-kwarg 51190) [x86_64-linux]) at "b/ruby"
-----------------------------------------------------------
raw data:

[["io_nonblock_noex",
  [[2.5436805468052626, 2.5724728293716908, 2.4915440678596497],
   [2.478000810369849, 2.4285155069082975, 2.462410459294915]]],
 ["io_nonblock_noex2",
  [[3.012514788657427, 3.034533655270934, 2.9972082190215588],
   [2.135501991957426, 2.146781364455819, 2.0429874528199434]]]]

Elapsed time: 30.348340944 (sec)
-----------------------------------------------------------
benchmark results:
minimum results in each 3 measurements.
Execution time (sec)
name    a       b
io_nonblock_noex        2.492   2.429
io_nonblock_noex2       2.997   2.043

Speedup ratio: compare with the result of `a' (greater is better)
name    b
io_nonblock_noex        1.026
io_nonblock_noex2       1.467

Note: I plan to followup commits for other *_nonblock methods
Eventually, I even wish to deprecate rb_scan_args :D

For what it's worth, I'm more excited about this change than usual
and hope to use prelude.rb more.
~~~


---Files--------------------------------
0001-io.c-avoid-kwarg-parsing-in-C-API.patch (6.88 KB)


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

  parent reply	other threads:[~2015-12-27 22:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11339.20150707215946@ruby-lang.org>
2015-07-07 21:59 ` [ruby-core:69892] [Ruby trunk - Feature #11339] [Open] [PATCH] io.c: avoid kwarg parsing in C API normalperson
2015-07-15 19:41   ` [ruby-core:69983] " Eric Wong
2015-07-16  3:46     ` [ruby-core:69990] " SASADA Koichi
2015-07-16  7:01       ` [ruby-core:69995] " Eric Wong
2015-07-16  9:17         ` [ruby-core:69999] " SASADA Koichi
2015-10-09 23:35           ` [ruby-core:71035] " Eric Wong
2015-11-10 22:27   ` [ruby-core:71435] " Eric Wong
2015-12-02  2:23   ` [ruby-core:71789] " Eric Wong
2015-11-11  5:20 ` [ruby-core:71439] [Ruby trunk - Feature #11339] " matz
2015-11-12  2:03   ` [ruby-core:71459] " Eric Wong
2015-11-12  9:53     ` [ruby-core:71462] " Eric Wong
2015-11-18  2:07     ` [ruby-core:71539] " Eric Wong
2015-11-13  4:18   ` [ruby-core:71473] " Eric Wong
2015-11-13  5:46     ` [ruby-core:71478] " SASADA Koichi
2015-11-13  7:03       ` [ruby-core:71479] " Eric Wong
2015-12-27 22:49 ` headius [this message]
2015-12-27 23:00 ` [ruby-core:72528] " headius
2015-12-27 23:40   ` [ruby-core:72529] " Eric Wong
2015-12-28  0:13 ` [ruby-core:72530] " headius
2015-12-28  1:12   ` [ruby-core:72532] " Eric Wong
2015-12-28  0:22 ` [ruby-core:72531] " headius
2015-12-28  1:50 ` [ruby-core:72535] " headius

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-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-55791.20151227224909.c19dfc49056ebdeb@ruby-lang.org \
    --to=ruby-core@ruby-lang.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).