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: 03 Feb 2004 15:17:38 +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 1075814759 2479 80.91.224.253 (3 Feb 2004 13:25:59 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 3 Feb 2004 13:25:59 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Tue Feb 03 14:25:52 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 1Ao0Yq-0001oq-00 for ; Tue, 03 Feb 2004 14:25:52 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1Ao0Yq-0007lz-00 for ; Tue, 03 Feb 2004 14:25:52 +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 1Ao0UV-0005yU-Tu for emacs-devel@quimby.gnus.org; Tue, 03 Feb 2004 08:21:23 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1Ao0Rg-0005eI-HL for emacs-devel@gnu.org; Tue, 03 Feb 2004 08:18:28 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1Ao0R1-0005V2-7N for emacs-devel@gnu.org; Tue, 03 Feb 2004 08:18:18 -0500 Original-Received: from [212.88.64.25] (helo=mail-relay.sonofon.dk) by monty-python.gnu.org with smtp (Exim 4.24) id 1Ao0Qz-0005UR-Vd for emacs-devel@gnu.org; Tue, 03 Feb 2004 08:17:46 -0500 Original-Received: (qmail 47007 invoked from network); 3 Feb 2004 13:17:44 -0000 Original-Received: from unknown (HELO kfs-l.imdomain.dk.cua.dk) (213.83.150.2) by 0 with SMTP; 3 Feb 2004 13:17:44 -0000 Original-To: Dmitry Antipov In-Reply-To: <401A7EFE.8030509@mail.ru> Original-Lines: 32 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:19683 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:19683 Dmitry Antipov writes: > Hello, > > 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: Nice idea, but in its current form it fails because the buf array is allocated on the stack. It may work to just declare it static though. > > What do you think about this idea ? I think it's ok, if we can guarantee that read_avail_input is never called recursively (I haven't checked). But I really wonder why it is necessary to initialize the array at all. It would seem more sensible simply to require that the functions which stuff things into an input_event do the EVENT_INIT themselves -- if necessary. Of course, it is more work to find these places, but it seems more correct to do it that way. BTW, it definitely is unnecessary to init the whole array if read_socket_hook is NULL; we could just init the first nread elements in that case. -- Kim F. Storm http://www.cua.dk