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 (smtp.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 2C03E19E002F for ; Mon, 28 Dec 2015 08:50:05 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 6965CB5D869 for ; Mon, 28 Dec 2015 09:22:39 +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 A13AE18CC7B5 for ; Mon, 28 Dec 2015 09:22:39 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 2A2F31205B5; Mon, 28 Dec 2015 09:22:31 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id 85E69120494 for ; Mon, 28 Dec 2015 09:22:21 +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=M6TkxagrM+RP6TC6K/ecE4YXSjE=; b=mXTOPAwNA8hxe11wDp 5L5IL+SBS+DQUEo57Dvrs6OWZNcTCv9BCG6ecJMPGTmQmbwz+N12GfssGHhm4+Eu xi60To2wyIlmxFig4lmKjU37V+s8ja1gARX+algEJv6ugn8m9mhN6iYUpvg0gISO E1TSG+RCN+V3EkdCi/TGo+WW4= Received: by filter0580p1mdw1.sendgrid.net with SMTP id filter0580p1mdw1.11438.568080B820 2015-12-28 00:22:16.552795674 +0000 UTC Received: from herokuapp.com (ec2-54-167-96-176.compute-1.amazonaws.com [54.167.96.176]) by ismtpd0006p1iad1.sendgrid.net (SG) with ESMTP id ysTVIqhnRL2L5cL4PYvboA for ; Mon, 28 Dec 2015 00:22:16.861 +0000 (UTC) Date: Mon, 28 Dec 2015 00:22:16 +0000 From: headius@headius.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 47131 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11339 X-Redmine-Issue-Author: normalperson X-Redmine-Sender: headius 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS7Fi21HaM2Ygd88a4jATiJcJBvCHZiNfPbL2j DcxTES1yng83xlLvwT4rpUJvLQ1pcVp53/5700gfheAElt9xO89wGUS8lgpMQjLqpbg9jYQb5ngeNG 9Avy6m5g/NM3NqstvLBX42jZXvh4xFSw/FxDubyhskDf/hC+8RAoNRClYQ== X-ML-Name: ruby-core X-Mail-Count: 72531 Subject: [ruby-core:72531] [Ruby trunk - Feature #11339] [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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11339 has been updated by Charles Nutter. Comparing stack traces: ``` [] ~/projects/ruby $ ruby23 -rsocket -e "t = TCPSocket.new('google.com', 80); t.read_nonblock(1)" :76:in `__read_nonblock': Resource temporarily unavailable - read would block (IO::EAGAINWaitReadable) from :76:in `read_nonblock' from -e:1:in `
' [] ~/projects/ruby $ ruby22 -rsocket -e "t = TCPSocket.new('google.com', 80); t.read_nonblock(1)" -e:1:in `read_nonblock': Resource temporarily unavailable - read would block (IO::EAGAINWaitReadable) from -e:1:in `
' ``` ---------------------------------------- Feature #11339: [PATCH] io.c: avoid kwarg parsing in C API https://bugs.ruby-lang.org/issues/11339#change-55796 * 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/