From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id gPIuHWPgR2U0pAAA9RJhRA:P1 (envelope-from ) for ; Sun, 05 Nov 2023 19:35:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id gPIuHWPgR2U0pAAA9RJhRA (envelope-from ) for ; Sun, 05 Nov 2023 19:35:15 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 227D2526B3 for ; Sun, 5 Nov 2023 19:35:15 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1699209315; a=rsa-sha256; cv=none; b=Xyk2bKN1ZM5Phz5NgYN0yu+Oft3RjHsBKIszVqcNOZJLLRU3q1vmkR5aF4aqouePiiPLr/ 6gGf1gG+qlgXuEnRthRKehg2mBj95W8Ef93X69Jehf2Dq1/ZtR73ts40/u0KMZExPRWQ6a e6ERNn86wqgdeOSVrGP/Owa7paAQqffM7Sc1SZ27XNho+ZevT8vLuEs0fhNAnQOj8ZLjUH Cv3EJyPXDjgzcsb22RqObmrnv4NCe0XywVZxGTDKMXjVhobHR6x6aDKgU/VbOOdColvoSo Xoj++8v9akh55D9HAdu4G1qKWbl4XHtQcmIMblx4U4q39wHAbMIa2D37X/aLDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1699209315; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-to:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post; bh=B6I/WX6XS7/HPsUD8gbtIP7XAJYx2ww0MPlYMHqYuJk=; b=TxC3p/hm9N2NNpbfzCxPH2McUH3SANWhxmrF1BzYF37CddBGFY3/vjuZ7FDTNwp7MtXVJ4 nCrri127IvMeGao0ivZnpXQPspaaolyOr07UshDh6zDYIiQ2IaiY5DDV4ukYaOS2I4nedm yVuaV6iPMjZCYE4AMqUbeA1ozkIJFrLbQzl4wHL9vxLlzaUNERtkxZo8ET18vCbOG+rH08 EfLFnmCSBoKTkpeKCj4lIJ7dyoBGjpmqTnRjesH/UwX5fjhOR26QTE7rRAaha74P6PhKv9 GnBv/QQ5/6QcY0wJtrCXGV96wAjM9jt8bODNxcmOpDgnMvRlGp0Yj+mEVGXg4A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qzhhc-0003B6-CH; Sun, 05 Nov 2023 13:18:28 -0500 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 1qzhhZ-0003AB-Vv for guix-patches@gnu.org; Sun, 05 Nov 2023 13:18:25 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qzhhZ-0007lu-MP for guix-patches@gnu.org; Sun, 05 Nov 2023 13:18:25 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qzhiA-0002kI-AS for guix-patches@gnu.org; Sun, 05 Nov 2023 13:19:02 -0500 Subject: bug#66796: [PATCH] lint: Speed up the formatting linter. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-To: guix-patches@gnu.org Resent-Date: Sun, 05 Nov 2023 18:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 66796 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 66796-done@debbugs.gnu.org Mail-Followup-To: 66796@debbugs.gnu.org, mail@cbaines.net, mail@cbaines.net Received: via spool by 66796-done@debbugs.gnu.org id=D66796.169920833910531 (code D ref 66796); Sun, 05 Nov 2023 18:19:02 +0000 Received: (at 66796-done) by debbugs.gnu.org; 5 Nov 2023 18:18:59 +0000 Received: from localhost ([127.0.0.1]:38155 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzhi7-0002jn-0M for submit@debbugs.gnu.org; Sun, 05 Nov 2023 13:18:59 -0500 Received: from mira.cbaines.net ([2a01:7e00:e000:2f8:fd4d:b5c7:13fb:3d27]:60457) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzhi4-0002je-RV for 66796-done@debbugs.gnu.org; Sun, 05 Nov 2023 13:18:57 -0500 Received: from localhost (unknown [193.218.17.244]) by mira.cbaines.net (Postfix) with ESMTPSA id 9C14A27BBE2; Sun, 5 Nov 2023 18:18:18 +0000 (GMT) Received: from felis (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id ae65e102; Sun, 5 Nov 2023 18:18:17 +0000 (UTC) References: <4499b0c65aa2b2578b1d2efd17cd9f91d97fd2a0.1698503714.git.mail@cbaines.net> <87zfzs1d5h.fsf@gnu.org> User-agent: mu4e 1.10.7; emacs 29.1 From: Christopher Baines Date: Sun, 05 Nov 2023 18:17:31 +0000 In-reply-to: <87zfzs1d5h.fsf@gnu.org> Message-ID: <87pm0ojc7q.fsf@cbaines.net> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx11.migadu.com X-Spam-Score: -5.84 X-Migadu-Queue-Id: 227D2526B3 X-Migadu-Spam-Score: -5.84 X-TUID: HFkAKorKYLN3 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s writes: > Hi, > > Christopher Baines skribis: > >> By storing the bytes to seek to for the start of each line the first tim= e you >> want to check a package in a file, rather than figuring out where the pa= ckage >> starts each time. >> >> This cuts down the time to run guix lint -c formatting from 450 seconds = to 13 >> seconds. > > Excellent! > >> + (define (seek-to-line port line) >> + (let ((offset >> + (vlist-ref >> + (or (hash-ref (%check-formatting-seek-lookup) file) >> + (call-with-input-file file >> + (lambda (port) >> + (let* ((buf-length 80) >> + (buf (make-string buf-length))) >> + (let loop ((byte-lookup-list '(0))) >> + (let* ((rv (%read-delimited! "\n" buf #t port)) >> + (terminator (car rv)) >> + (nchars (cdr rv))) >> + (cond >> + ((eof-object? terminator) >> + (let ((byte-lookup-vlist >> + (list->vlist >> + (reverse byte-lookup-list)))) >> + (hash-set! (%check-formatting-seek-lookup) >> + file >> + byte-lookup-vlist) >> + byte-lookup-vlist)) >> + >> + ((not terminator) >> + (loop byte-lookup-list)) >> + >> + (nchars >> + (loop (cons >> + (ftell port) >> + byte-lookup-list)))))))))) >> + (- line 1)))) >> + (set-port-line! port line) >> + (seek port offset SEEK_SET) >> + line)) > > Two things: (1) it=E2=80=99s a bit hard to read, in part due to long > identifiers, and (2) it would be nice to keep this facility orthogonal, > outside the checker. > > As it turns out, a similar facility is available in (guix utils), > exposed via =E2=80=98go-to-location=E2=80=99. Would it be possible to us= e it here? > >> + (let loop ((line-number >> + (if (%check-formatting-seek-lookup) >> + (seek-to-line port starting-line) >> + 1)) > > Answering myself: I guess =E2=80=98seek-to-line=E2=80=99 can be replaced = by > (go-to-location port starting-line 0). Cool, this simplifies the change a lot, I've pushed the amended version to master as aa98a976079101318d53b412fef6c722bb4332c9. Thanks, Chris --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmVH3GlfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh aW5lcy5uZXQACgkQXiijOwuE9Xfz7g/7B5Y5SFSnjIU9G5M+eZqFOz/FQcUSgobp FWfziNHnc3VpCvEd9f//oVFwkGJtDwP/aex9kCmTeaK76itNJsiu0TI2TpaReCcR l/me1agFyjR2j9mpf3cOdr9VFbenQ1ZryuolZxulNNTee4+fRTOKDTqOarDufc4I WjPKGse6BV1qLA4Ppt1f4OtjfwzyRMCes3HzIrxdUAYSAksj4qTJ33Kc7fDIn6jo o4m78JCIMZWDsKIUlW6VOZ6wSLK/R4xZB8nOW2l4d+HQYjniPvujOO7DZzRt6oYj EJNdMSAmjuNKybFhBwzqS7Vs3OAf9UgdM+7mwBbEPyLMlXC238K/ssuVo/885nCe yDklanS2hz4ugVPqWSj9kpy9fVPbQGtbDJXnyWrGY+UaG3Tzbmkcci8L/kDjyFSk 99iSVTunm0oOqZkaWC/MowVVamrtiwrJ3amwalqQpvGdoDbFFan7LtJQohu70rEb y+G2Z6gzlQL2SaRfRiazUhgFdJ5qsvlNwRZu9USRFWQ2SP2wo6ipjKhFy2Zonu5F szQyxWNIuPlowfkDSrncvsUasDL4Tc3EHPQ1LH866EygSaeaqpxduESp9aT0/UmR TT+eRX/bY5aubmTPEci1mhmUZXq998vrl1Pzq2vOnL9NIJvrDibTpsSzdHnZBQD6 zNvPdrBjGxQ= =VFYY -----END PGP SIGNATURE----- --=-=-=--