From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: Simple optimization for read_avail_input() Date: 18 Feb 2004 00:51:29 +0100 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: <401A7EFE.8030509@mail.ru> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1077058457 4592 80.91.224.253 (17 Feb 2004 22:54:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 17 Feb 2004 22:54:17 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Tue Feb 17 23:54:11 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AtE6V-0008C1-00 for ; Tue, 17 Feb 2004 23:54:11 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1AtE6V-0004fb-00 for ; Tue, 17 Feb 2004 23:54:11 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AtE6C-0001Ib-GW for emacs-devel@quimby.gnus.org; Tue, 17 Feb 2004 17:53:52 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AtE4p-0001Ag-1g for emacs-devel@gnu.org; Tue, 17 Feb 2004 17:52:27 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AtE48-0000rp-HA for emacs-devel@gnu.org; Tue, 17 Feb 2004 17:52:15 -0500 Original-Received: from [195.41.46.236] (helo=pfepb.post.tele.dk) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AtE48-0000rV-6F for emacs-devel@gnu.org; Tue, 17 Feb 2004 17:51:44 -0500 Original-Received: from kfs-l.imdomain.dk.cua.dk (0x503e2644.bynxx3.adsl-dhcp.tele.dk [80.62.38.68]) by pfepb.post.tele.dk (Postfix) with SMTP id 43E295EE100; Tue, 17 Feb 2004 23:51:42 +0100 (CET) Original-To: Dmitry Antipov In-Reply-To: <401A7EFE.8030509@mail.ru> Original-Lines: 39 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:20031 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20031 Dmitry Antipov writes: > Hello, > > this is a top of gprof output for Emacs CVS snapshot. It was being compiled with > '-O0 -ftest-coverage -g -pg -fprofile-arcs', started and finished with C-x C-c > immediately: > > Flat profile: > > Each sample counts as 0.01 seconds. > % cumulative self self total time > seconds seconds calls ms/call ms/call name 12.12 > 0.04 0.04 2464 0.02 0.02 ccl_driver > 12.12 0.08 0.04 546 0.07 0.07 read_avail_input > 9.09 0.11 0.03 23731 0.00 0.00 read1 > 9.09 0.14 0.03 4452 0.01 0.01 mark_object > 6.06 0.16 0.02 289315 0.00 0.00 readchar > 6.06 0.18 0.02 8335 0.00 0.00 Fbyte_code > 6.06 0.20 0.02 743 0.03 0.03 Fassoc > 3.03 0.21 0.01 136877 0.00 0.00 translate_char > > It's clear here that very simple function read_avail_input() wastes a lot of > CPU time. IMHO this is because it wants to zero large 'struct input_event buf' > (which is KBD_BUFFER_SIZE (4096, except old MacOSs) * sizeof (struct input_event) > (44 bytes on 32-bit systems)) every time. But we can clear all 'buf' only once > and clear only used slots next time. The following patch illustrates this idea: Hi Dmitry, Your patch was installed in CVS yesterday, but it had some problems, so I reworked it quite a bit. I don't know if the intended effect on read_avail_input is still present with my changes, so I would ask you to redo your measurements to see if my changes are ok. Can you do that? -- Kim F. Storm http://www.cua.dk