From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 2D1C11960130 for ; Wed, 8 Jul 2015 06:33:17 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 1535BB5D8DE for ; Wed, 8 Jul 2015 07:00:13 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id BB88997A820 for ; Wed, 8 Jul 2015 07:00:13 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uff775Davcrq for ; Wed, 8 Jul 2015 07:00:13 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 7F8C497A82C for ; Wed, 8 Jul 2015 07:00:13 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id AE699952439 for ; Wed, 8 Jul 2015 07:00:12 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E739712046A; Wed, 8 Jul 2015 07:00:04 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 2FE01120419 for ; Wed, 8 Jul 2015 06:59:52 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=ZrgWft0redYmwVJVc5V5mT+As2o=; b=SFd4edPSE6rzHfAPCW m3bZmTyz3oYD2G3gr4b1tYvKC53726Anf4XFIgqLvIGrRADr/yUmywNKZDzvk+wF Ftog5+EBSPpik71c2lyMuRl2eom8+dP3ZTOLI9IyZUeJw/UcATMbDumt5MgBleWe 4+BabYGsUnoa1JUb8bqxCH0LA= Received: by filter0824p1mdw1.sendgrid.net with SMTP id filter0824p1mdw1.893.559C4BD415 2015-07-07 21:59:48.581123155 +0000 UTC Received: from herokuapp.com (ec2-54-211-56-213.compute-1.amazonaws.com [54.211.56.213]) by ismtpd-002 (SG) with ESMTP id 14e6a8831bb.6c53.5df031 for ; Tue, 07 Jul 2015 21:59:47 +0000 (UTC) Date: Tue, 07 Jul 2015 21:59:47 +0000 From: normalperson@yhbt.net To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 44502 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11339 X-Redmine-Issue-Author: normalperson X-Redmine-Sender: normalperson X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4JdC9KKycJ0hUY0lMzrG+qFxKJeQvvaUteIL hd9WFUSSVbHuBY/GenNtfp745YqnnX8YAfr3f+W6djDUUs7f+a7GAJvrnOSJDiwfYyG0nuQwX/XvNc G2QYrZWGibfYwTTjlukVL5J0xWT0EiALxr5c X-ML-Name: ruby-core X-Mail-Count: 69892 Subject: [ruby-core:69892] [Ruby trunk - Feature #11339] [Open] [PATCH] io.c: avoid kwarg parsing in C API X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/