From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Existing redisplay profiling tool? Date: Sun, 15 Sep 2024 23:16:48 -0700 Message-ID: <2A088262-BE9A-4289-A55A-128FB3D8E229@gmail.com> References: <18DF89D6-9434-4F37-A14A-B9396A68A8F7@gmail.com> <86y13udpbi.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7462"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 16 08:18:05 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sq53l-0001hU-GK for ged-emacs-devel@m.gmane-mx.org; Mon, 16 Sep 2024 08:18:05 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sq52u-0000nm-QZ; Mon, 16 Sep 2024 02:17:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sq52q-0000m3-PR for emacs-devel@gnu.org; Mon, 16 Sep 2024 02:17:08 -0400 Original-Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq52n-0004cf-CB; Mon, 16 Sep 2024 02:17:07 -0400 Original-Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-2d8fa2ca5b1so2363411a91.3; Sun, 15 Sep 2024 23:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726467423; x=1727072223; darn=gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Wy7ng31W+w5C8aAelmK7J8Cz5Xp1S3XiMVrCaEfIFsE=; b=XA2fqRWUF6t5UuXcWPPr5geeKHJReT1JHjtTkMbkawrNUkaoGOqkUW7V9HMQkEp1i4 slSubybCCOImo0sYY8znNxCEL7jcm7UT89GKs0y9vTlBZqsm0H8TsTs6SrgNgFO+Qb/8 +n/8xYXP5dkgBUiVBaiLQQlDonptS1g7PBscC3Rs10wsuTKiiObC96E5hf6R7ePOqKP+ 4rVxSXihb/lIwj+cn5INu38907txzTvH1XBoxIsQD/C19nx/cAaA89meu9SHZTgbl1we N1y1sbZvpf8L8oL++8Heqlswp898ZwsepAzHZzlHtH25QFnfSeD+F/7WHtpxTRzU2Obj +axQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726467423; x=1727072223; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wy7ng31W+w5C8aAelmK7J8Cz5Xp1S3XiMVrCaEfIFsE=; b=ZJ8fWPQt01h4LwB13w55gkXxXl5Q1NY0wIsBgGBXpaiUYBGEJS59JM3M1jtm9DwcH6 KRr177ZFx5yDdP8bxz0KC5NEVpdKOaUpkty9Pa4ZRoy56IZEf4vjA9IZiaZD0gwfbQKo qbF7lLU93xm/HjsZ/sJA9vxdDW5GlFS92tsqaHPczkNp3b2w9NEvKWpJSMUZi6XWtXWl cBAg8O1l4gMey0bGlyEAIwzaAbFgqcasiS49BCfAaomvBNHzTZH+wLwoxzcg17h4VLW7 qI6JVzeOKcaYI2HPHNCtlMi+JliYTjBUHLWD6thECuKMUrUJaE9CR8NjOBUaQKQMp7Iv bTpA== X-Gm-Message-State: AOJu0Yz45I7shqEsV/BvBe+j7U+55uRGUpv83bEoh4UXh1n3jWwbl3tl PwxwZB5riHTM4OwaHtwyBeJTSrtu0/sfQbkPnx0GGXWj9bxkCNhIbGArQA== X-Google-Smtp-Source: AGHT+IGzSqqulbTAUwyvoRZzwJA/FNn5TgkAzbrcpJNWX2ZNlOHIII3Yh7ydQBToJXkfoQ/AlkkgYw== X-Received: by 2002:a17:90b:682:b0:2da:5028:cfb9 with SMTP id 98e67ed59e1d1-2dbb9dc94acmr15165219a91.4.1726467423014; Sun, 15 Sep 2024 23:17:03 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:c75:3002:9563:938e]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dbb9d5c9d1sm6433255a91.35.2024.09.15.23.17.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Sep 2024 23:17:02 -0700 (PDT) In-Reply-To: <86y13udpbi.fsf@gnu.org> X-Mailer: Apple Mail (2.3776.700.51) Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=casouri@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:323655 Archived-At: > On Sep 14, 2024, at 12:10=E2=80=AFPM, Eli Zaretskii = wrote: >=20 >> From: Yuan Fu >> Date: Sat, 14 Sep 2024 11:20:15 -0700 >>=20 >> I=E2=80=99m doing some optimization for tree-sitter font-lock, and = want to measure the difference in a real editing session (rather than = fontifying the whole buffer 10 times). I=E2=80=99m sure there=E2=80=99s = some tool for measuring time spent in redisplay some where, but = couldn=E2=80=99t find anything poking around. >=20 > How about using the scrolling benchmark through xdisp.c while > profiling? >=20 > (defun scroll-up-benchmark () > (interactive) > (let ((oldgc gcs-done) > (oldtime (float-time))) > (condition-case nil (while t (scroll-up) (redisplay)) > (error (message "GCs: %d Elapsed time: %f seconds" > (- gcs-done oldgc) (- (float-time) oldtime)))))) >=20 > Evaluate the above, then turn on profiling, then type > "M-x scroll-up-benchmark RET" with point at beginning > of buffer that visits xdisp.c under c-ts-mode. Thanks! I=E2=80=99m hoping to measure the perceived responsiveness when = typing text in the buffer, so here=E2=80=99s what I came up with: (let ((prev-time (current-time)) (measurements nil)) (dotimes (_ 100) (insert "s") (redisplay) (push (float-time (time-subtract (current-time) prev-time)) measurements) (setq prev-time (current-time))) (message "Average time: %f" (/ (apply #'+ measurements) (length measurements)))) Do you think this accurately measures the redisplay time between each = keystroke? (Obviously this doesn=E2=80=99t take account of = post-command-hook, I only want to measure repose & redisplay here.) If that=E2=80=99s an accurate measurements, then my optimization = doesn=E2=80=99t make any significant difference :-) In xdisp.c, inserting 100 =E2=80=9Cs=E2=80=9D takes about 17.8ms per = =E2=80=9Ckeystroke=E2=80=9D on average. With optimization it=E2=80=99s = about 16.7ms, not much difference. Obviously the time differs depending on where are you inserting the = =E2=80=9Cs=E2=80=9D, but I tried a few places (close to beginning of = buffer, close to end, inside a function, outside a function, etc), and = the measurements doesn=E2=80=99t vary too much (12=E2=80=9316ms with = optimization on) I also measured a base performance by enabling fundamental-mode in = xdisp.c. It takes about 2.2ms between each =E2=80=9Ckeystroke=E2=80=9D. In a very small file, the average time between each =E2=80=9Ckeystroke=E2=80= =9D is 3.2ms and 3.5ms, for optimized and unoptimized run respectively. Finally, c-mode in xdisp.c takes about 10.7ms per =E2=80=9Ckeystroke=E2=80= =9D ;-) I guess the takeaway is a) my new optimization doesn=E2=80=99t do = anything, and b) tree-sitter font-lock doesn=E2=80=99t add = human-perceivable latency when typing. Yuan My measurements: xdisp.c: optimization off: Average time: 0.017755 -> 17.8ms optimization on: Average time: 0.016701 -> 16.7ms fundamental mode: Average time: 0.002188 -> 2.2ms optimization on w/ post-command-hook: Average time: 0.033086 -> 33.1ms small file: optimization on: Average time: 0.003207 -> 3.2ms optimization off: Average time: 0.003473 -> 3.5ms optimization on w/ post-command-hook: Average time: 0.013553 -> 13.6ms c-mode: xdisp.c : Average time: 0.010691 -> 10.7ms small file: Average time: 0.005141 -> 5.1ms=