CARVIEW |
Select Language
HTTP/2 200
x-amz-id-2: Ru7lhtJmBDv+/GIZLkxgvWRYBxlXCqx8BQbVgpVTUpRdWyUHztN1JJaVh/WTkxdbmT/uZKfAXOk=
x-amz-request-id: NYQWGBPRJPPTS3VR
last-modified: Fri, 02 Dec 2022 04:05:59 GMT
etag: "7e9ba1314b1fa7ed467ddd8cfea11d5e"
server: AmazonS3
content-encoding: gzip
via: 1.1 varnish, 1.1 varnish
content-type: text/plain; charset=utf-8
accept-ranges: bytes
age: 0
date: Mon, 21 Jul 2025 14:29:46 GMT
x-served-by: cache-tyo11941-TYO, cache-bom4748-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753108187.604822,VS0,VE309
vary: Accept-Encoding
content-length: 1165
From: normalperson@...
Date: 2015-07-07T21:59:47+00:00
Subject: [ruby-core:69892] [Ruby trunk - Feature #11339] [Open] [PATCH] io.c: avoid kwarg parsing in C API
Issue #11339 has been reported by Eric Wong.
----------------------------------------
Feature #11339: [PATCH] io.c: avoid kwarg parsing in C API
https://bugs.ruby-lang.org/issues/11339
* Author: Eric Wong
* Status: Open
* 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/