From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id eE/xHlRKd2KE/AAAbAwnHQ (envelope-from ) for ; Sun, 08 May 2022 06:43:00 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id QF0SHlRKd2LceAEAG6o9tA (envelope-from ) for ; Sun, 08 May 2022 06:43:00 +0200 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 26EFA43D36 for ; Sun, 8 May 2022 06:43:00 +0200 (CEST) Received: from localhost ([::1]:57074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nnYl0-0002uJ-Sf for larch@yhetil.org; Sun, 08 May 2022 00:42:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nnYkK-0002uA-6F for emacs-orgmode@gnu.org; Sun, 08 May 2022 00:42:16 -0400 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]:39521) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nnYkH-0002kf-KS for emacs-orgmode@gnu.org; Sun, 08 May 2022 00:42:15 -0400 Received: by mail-oi1-x230.google.com with SMTP id l16so11968793oil.6 for ; Sat, 07 May 2022 21:42:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=+ciR7a2lUOENxS6OdZg6lZx7CXsLId5qOw94DYLXcb8=; b=P6FqpJwvJ0FtYObmkYTXEpnaq6oObzoQITZmXgH2gBtybmwzvzRt8xlx/mB9sFH4k6 UuCMoWsXi7eJibtITjXV9eNGGjRqk4ZiBPjCHIVDFuZf4+GgWtjzrhzauR1GgO8spoaZ taxm6NTXogAvJJsM2h8eJJ5jorI3iaLfy18Z+Sv6JcKhqX91YEZeW9W2u+Cj8NBCcW99 mHrPJNU820FWjsaSs7hgQZ8akTOk5UazAZZ98Gaes1lSWdlTKBX3bkXtf0+6Ci8Zbn+9 /XfDrzBnbPfo+vxEJxxLq0RhZYjTcmHdYz8rTGgcRDvJzIfjPqHRXeJ7sk2j6x90hjFE rOLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=+ciR7a2lUOENxS6OdZg6lZx7CXsLId5qOw94DYLXcb8=; b=2ZGXgOUF+RaEeHzBrveNyaYPvFA/OdeLtLmb5E6WyK+uB86qYvBPcueNylTK0F8fdI ycgmpQrNk7aRMr2euLJRV/rii7N/Kx96GPCiSt6s/PB5nBoLcu3NpkU5fqasJeGSFog1 Dp1taGVnMHTIA8N084WwuMbfPbOd58xiFtkQifR8+q9HED+FG9SNfg3ER//1aYOjxg0W sFGoSYbvgWKnnUqcE6FH+qKdEUMKmI+p456iIos+I4hZsKkszlGNnXO1/2QdB/Rrkw3c QhxxjOf9YlSdeg62eMQ0suQ4ScPIXGlCvpDSRvVJf+YvhiqYWm5CmH8iUsXbUrq75M9m l2zg== X-Gm-Message-State: AOAM530z5pKzFmC9RVj49La+Pde/vFWIZXSsADOV+6omVxWGlUg/ufM7 wdUn8onnDyvFOjCWDkusU88= X-Google-Smtp-Source: ABdhPJzSVPly7sdE+9kJhc4ZEsYfZniQAC3AovI+YHZZ5XADAeYhR9hXsd7gY6mUgtKvD1d/09eZDA== X-Received: by 2002:a05:6808:170d:b0:2f7:3e70:fdb3 with SMTP id bc13-20020a056808170d00b002f73e70fdb3mr8494804oib.139.1651984932384; Sat, 07 May 2022 21:42:12 -0700 (PDT) Received: from localhost ([104.223.98.2]) by smtp.gmail.com with ESMTPSA id w8-20020a056870a2c800b000e686d1387asm2908576oak.20.2022.05.07.21.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 May 2022 21:42:11 -0700 (PDT) From: Ihor Radchenko To: Max Nikulin Cc: Greg Minshall , Org Mode Subject: [PATCH] Re: tangle option to not write a file with same contents? In-Reply-To: <12cd2bb0-584e-dcff-baca-1ed27d0281ff@gmail.com> References: <583051.1635393898@apollo2.minshall.org> <12cd2bb0-584e-dcff-baca-1ed27d0281ff@gmail.com> Date: Sun, 08 May 2022 12:42:53 +0800 Message-ID: <878rrcws6q.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::230; envelope-from=yantar92@gmail.com; helo=mail-oi1-x230.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1651984980; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=+ciR7a2lUOENxS6OdZg6lZx7CXsLId5qOw94DYLXcb8=; b=koPbHyLCk97Q6GuK1tSyLD6QaiuKD605w8KfTNjacVydU5CHFNzlChTzGawN1Mrpg4qHp/ vgDkJqJ+xKrmHBUXCHC0b0P5ob/iSOrC4L+G9MGuxCvO84/F9GHIBI4/JVUXy+F1TS8mZ3 xCPAs2oENPjZpuQUYkmsaoSq2FRfqFUkBaTVx9RyVJHiCW+SzqhL4ZsY5m0MilmpImr6vM /ZTbUaXuSbYU7JNiotcSTK4J+r+HN/T5MAGGg/weywDKDp/HKTPvwOYg+2M7fOf0B/ZaMi q2pGH2Xz8Mpv71RkZQ6+QkeHYpN+DemEsslmPKYEJ8zv/Q+bI1k4RLwJStqF4g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1651984980; a=rsa-sha256; cv=none; b=Doagxlzj6AWPLUFMaNh8HWSl3t74ZeO78A7byGwFE8zy8nJbWJaKJ39Oizl01pMMrXkQH/ G41mkVKR6BmsOWo4tca8uqMESWtaRtvGd81tUgd0gpUG2lz9PhinLpDu5h/6Wly7XnQCja dWckBiiutorLP5PQ7BvcWODVohLWHPm+mz+tce10aK08fzj5MrEkVNpaNt1a1AxYjVRk0w /GNWVa86bLm2y2XIs9Pwv3sQ/Hq7ZxcyHnS4wTw1yVO+X28vjYJ8GUP33vAMz+CDfK81TU SLK4n9mf7Wn4WsjTodburaQYC9AZ7kdacE+GiSmo1Hum9/vKxyTG9fUi+bn3dQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=P6FqpJwv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -4.30 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=P6FqpJwv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 26EFA43D36 X-Spam-Score: -4.30 X-Migadu-Scanner: scn0.migadu.com X-TUID: KUAy67i0mh+i --=-=-= Content-Type: text/plain Max Nikulin writes: > On 28/10/2021 11:04, Greg Minshall wrote: >> >> i wonder if it would be reasonable to add an option such that, when >> tangling, `org-babel-tangle` would not write a file with the >> already-existing contents of the target file? >> >> this would be helpful, e.g., for those of us who use make(1)-based work >> flows. > > It was not obvious for me earlier that it should be namely an *option*, > not just change of behavior, since e.g. `org-babel-load-file' relies on > timestamp comparison of the source .org file and the derived .el file. I > am unsure concerning default value of such setting. I agree that it should be the default behaviour. The patch is attached. On SSD, when tangling into ~200 files, the patch speeds up tangling by almost 2x: before 7.6 sec; after 4.4 sec. Best, Ihor --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-tangle-Do-not-overwrite-when-contents-does-not-c.patch >From 68d90e73da17e423220211897ad1e86a4eb2e5a1 Mon Sep 17 00:00:00 2001 Message-Id: <68d90e73da17e423220211897ad1e86a4eb2e5a1.1651984776.git.yantar92@gmail.com> From: Ihor Radchenko Date: Sun, 8 May 2022 12:32:40 +0800 Subject: [PATCH] org-tangle: Do not overwrite when contents does not change * lisp/ob-tangle.el (org-babel-tangle): Do not overwrite existing tangled files if their contents is exactly the same as we are going to write during tangle process. This avoids unneeded disk writes and can speed up tangling significantly when many small files are tangles from a single .org source. An example of performance improvement when tangling an .org file into ~200 files: (benchmark-run 10 (org-babel-tangle)) Before the commit (on SSD): (76.33826743 8 11.551725374) After the commit: (43.628606052 4 5.751274237) --- lisp/ob-tangle.el | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 16d938afb..c011bf662 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -282,11 +282,17 @@ (defun org-babel-tangle (&optional arg target-file lang-re) lspecs) (when make-dir (make-directory fnd 'parents)) - ;; erase previous file - (when (file-exists-p file-name) - (delete-file file-name)) - (write-region nil nil file-name) - (mapc (lambda (mode) (set-file-modes file-name mode)) modes) + (unless + (let ((new-contents-hash (buffer-hash))) + (with-temp-buffer + (when (file-exists-p file-name) + (insert-file-contents file-name)) + (equal (buffer-hash) new-contents-hash))) + ;; erase previous file + (when (file-exists-p file-name) + (delete-file file-name)) + (write-region nil nil file-name) + (mapc (lambda (mode) (set-file-modes file-name mode)) modes)) (push file-name path-collector)))))) (if (equal arg '(4)) (org-babel-tangle-single-block 1 t) -- 2.35.1 --=-=-=--