From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.org!.POSTED!not-for-mail
From: Anders Lindgren <andlind@gmail.com>
Newsgroups: gmane.emacs.devel
Subject: Re: Making font-lock handle long lines better
Date: Sun, 12 Feb 2017 00:06:41 +0100
Message-ID: <CABr8ebY_0sUTmv_unYQSdZ4VjrCf3KNH3nnE2SW_sd-xEdU9+A@mail.gmail.com>
References: <CA+caGh_JN9FRi71VjUTwvYBKKygG-KuGGoe3GBgjthPRh00nRg@mail.gmail.com>
	<83wpcy2eun.fsf@gnu.org>
	<CAFXAjY4ED1L=T1zB-v=U-_DWbkOaO8+4cDidejBunS-RC3D7zQ@mail.gmail.com>
	<83lgtc3215.fsf@gnu.org>
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a114e1ce27876910548494490
X-Trace: blaine.gmane.org 1486854413 11745 195.159.176.226 (11 Feb 2017 23:06:53 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 11 Feb 2017 23:06:53 +0000 (UTC)
Cc: Wilfred Hughes <me@wilfred.me.uk>, public@ryanb.org,
	emacs-devel <emacs-devel@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Feb 12 00:06:49 2017
Return-path: <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>
Envelope-to: ged-emacs-devel@m.gmane.org
Original-Received: from lists.gnu.org ([208.118.235.17])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>)
	id 1ccgki-0002dA-GS
	for ged-emacs-devel@m.gmane.org; Sun, 12 Feb 2017 00:06:48 +0100
Original-Received: from localhost ([::1]:49911 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>)
	id 1ccgko-0001O4-6D
	for ged-emacs-devel@m.gmane.org; Sat, 11 Feb 2017 18:06:54 -0500
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48978)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <andlind@gmail.com>) id 1ccgkh-0001Ny-Km
	for emacs-devel@gnu.org; Sat, 11 Feb 2017 18:06:48 -0500
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <andlind@gmail.com>) id 1ccgkg-0005rk-AS
	for emacs-devel@gnu.org; Sat, 11 Feb 2017 18:06:47 -0500
Original-Received: from mail-vk0-x232.google.com ([2607:f8b0:400c:c05::232]:32775)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
	(Exim 4.71) (envelope-from <andlind@gmail.com>)
	id 1ccgke-0005rW-Dk; Sat, 11 Feb 2017 18:06:44 -0500
Original-Received: by mail-vk0-x232.google.com with SMTP id k127so44847279vke.0;
	Sat, 11 Feb 2017 15:06:42 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
	h=mime-version:in-reply-to:references:from:date:message-id:subject:to
	:cc; bh=tPYu5d/Svx7ab4/QoyxHhSdtL4EVGLNreteC209+8Co=;
	b=q/Ke9igrjR8v9omEqfZQD2shwBEX+1bElH0i1j8lSI+suD6YuRIPakOq/m/VZ+gNTZ
	E3eo/WwPXvyBLNmuKECi2KrZZQGbdTOHDeN8o9DRa3NKQ+qHUN7zxPFPsoa0ADADcKxp
	1qo30sLREGzyr5Fp4JqICsU0/ru5UP3LF4z3IV4gn0f+QqJ2C3WY7bdlWRLeI4MhgwYw
	Z/uGkYOA45GnTWIO5sKzKeL3keiInuLFLrLB1cZ1DOt+fz9yyfD0cAh6F5oKtUzzhyTh
	1SpCz71M/JhykuF1dYX8lVkHysPWsTb78DBgTVff80uOjI6QpI4u4EsfbvC27Qc+YWiJ
	Gz8A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:mime-version:in-reply-to:references:from:date
	:message-id:subject:to:cc;
	bh=tPYu5d/Svx7ab4/QoyxHhSdtL4EVGLNreteC209+8Co=;
	b=WWRQppDL+y605vI1bwIGiGaDZ6dULTswfJ9eVlZE1f7tGx+D+i1o8GG/W9og643rhG
	cbNIL639VQ5mKQIBUdqruA097tlP0qbvHP3HgVBfiljX5dtmfFB+lhtImC8rsb302iCS
	WQZC3d27gSs2cygWJSyr0kA+g1Nf/KMnoqIKeNfFeO/9vUBS0t3QQoKKPJqJxsbUfCB/
	cCB+YIlciSl0Py0RiXsCELg8fUnrwX+UrKQDD64bpMOwQ/O6cZMzLq+3tFG2QTWLbcCN
	4YlnVJ0KBRDqoiRLTRDD2gn1J1eoV2LbbdGjvEwLuj3WvufAetqp5mi7q60TwdBp266f
	kHVA==
X-Gm-Message-State: AMke39n2Op1n+SctE2ZjE+AuwnT5HQ93Kt+NZ5hpBKEmGqEbKlKrTPm6kUhaTfuBmNh3qFXvEX9AnBldJlR5dw==
X-Received: by 10.31.208.133 with SMTP id h127mr8024489vkg.96.1486854402108;
	Sat, 11 Feb 2017 15:06:42 -0800 (PST)
Original-Received: by 10.31.52.129 with HTTP; Sat, 11 Feb 2017 15:06:41 -0800 (PST)
In-Reply-To: <83lgtc3215.fsf@gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2607:f8b0:400c:c05::232
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-devel>,
	<mailto:emacs-devel-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/emacs-devel/>
List-Post: <mailto:emacs-devel@gnu.org>
List-Help: <mailto:emacs-devel-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-devel>,
	<mailto:emacs-devel-request@gnu.org?subject=subscribe>
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org
Original-Sender: "Emacs-devel" <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>
Xref: news.gmane.org gmane.emacs.devel:212250
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/212250>

--001a114e1ce27876910548494490
Content-Type: text/plain; charset=UTF-8

>
> Since it's slow in Fundamental mode as well, it's unrelated to
> font-lock, and thus to this thread.  Display of very long lines is
> known to be slow in Emacs.
>

I believe this is a font-lock problem. If you disable global-font-lock-mode
before you open the file, it opens in seconds. If global-font-lock-mode is
active Emacs stops responding (I gave up after a few minutes).

A quick experiment suggested that the problem is the member
`font-lock-extend-region-wholelines' of `font-lock-extend-region-functions'
that ensures that whenever font-lock highlights keywords in a region, the
full line is rehighlighted (in the case of the example, the full 18M). By
removing it, font-locking the file is done in seconds. (I assume that only
the visible parts of the buffer is highlighted.)

Clearly, simple dropping the function is not a good idea, as keyword
fontification could start anywhere on the line, e.g. in the middle of
identifiers. A better approach would be to extend the region to include
10KB in either direction, plus ensure that the region isn't split in the
middle of identifiers.

   / Anders

Ps. In case anybody is interested in looking further into this, you can use
the tool https://github.com/Lindydancer/highlight-refontification to get
visual feedback on the font-lock refontification process.

--001a114e1ce27876910548494490
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote"><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left=
:1px solid rgb(204,204,204);padding-left:1ex">Since it&#39;s slow in Fundam=
ental mode as well, it&#39;s unrelated to<br>
font-lock, and thus to this thread.=C2=A0 Display of very long lines is<br>
known to be slow in Emacs.<br></blockquote><div><br></div><div>I believe th=
is is a font-lock problem. If you disable global-font-lock-mode before you =
open the file, it opens in seconds. If global-font-lock-mode is active Emac=
s stops responding (I gave up after a few minutes).</div><div><br></div><di=
v>A quick experiment suggested that the problem is the member `font-lock-ex=
tend-region-wholelines&#39; of `font-lock-extend-region-functions&#39; that=
 ensures that whenever font-lock highlights keywords in a region, the full =
line is rehighlighted (in the case of the example, the full 18M). By removi=
ng it, font-locking the file is done in seconds. (I assume that only the vi=
sible parts of the buffer is highlighted.)</div><div><br></div><div>Clearly=
, simple dropping the function is not a good idea, as keyword fontification=
 could start anywhere on the line, e.g. in the middle of identifiers. A bet=
ter approach would be to extend the region to include 10KB in either direct=
ion, plus ensure that the region isn&#39;t split in the middle of identifie=
rs.</div><div><br></div><div>=C2=A0 =C2=A0/ Anders</div><div><br></div><div=
>Ps. In case anybody is interested in looking further into this, you can us=
e the tool=C2=A0<a href=3D"https://github.com/Lindydancer/highlight-refonti=
fication">https://github.com/Lindydancer/highlight-refontification</a> to g=
et visual feedback on the font-lock refontification process.</div><div><br>=
</div></div></div></div>

--001a114e1ce27876910548494490--