From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: Re: speeding up Babel Gnuplot Date: Tue, 03 Jan 2017 22:40:35 +0100 Message-ID: <586C1A53.90601@free.fr> References: <5864217C.7060001@free.fr> <586963CB.1000006@free.fr> <87d1g6qrqh.fsf@nicolasgoaziou.fr> <586AB3DB.6070702@free.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030103060300010908010205" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOWp1-0007EK-6x for emacs-orgmode@gnu.org; Tue, 03 Jan 2017 16:40:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cOWoy-0001XY-2U for emacs-orgmode@gnu.org; Tue, 03 Jan 2017 16:40:43 -0500 Received: from smtp1-g21.free.fr ([212.27.42.1]:53262) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cOWox-0001Sd-QA for emacs-orgmode@gnu.org; Tue, 03 Jan 2017 16:40:40 -0500 Received: from [IPv6:2a01:e35:2e21:def0:5c6:c54e:521f:2c36] (unknown [IPv6:2a01:e35:2e21:def0:5c6:c54e:521f:2c36]) by smtp1-g21.free.fr (Postfix) with ESMTP id F0417B00305 for ; Tue, 3 Jan 2017 22:40:35 +0100 (CET) In-Reply-To: <586AB3DB.6070702@free.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------030103060300010908010205 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Here is a patch to avoid generating temporary files multiple times. There is no way to ensure a single call to (org-babel-gnuplot-process-vars) without modifying ob-core.el. I don't want to do that because I would have to change a lot of babel backends. Thus, I come back to my first light patch. A 'param' list is passed around. It reflects the #+BEGIN_SRC header. My patch changes it in-place from: (((:var data (3000) (2999) (2998) (2997) ... to: (((:var data . "/tmp/babel-16991kSr/gnuplot-16991YBq") ... The 'param' list behaves as a cache. There is nothing wrong with that. The worst thing that can happen is the caching no longer working in case 'param' would be copied some day. Results would stay correct. Regards, Thierry --------------030103060300010908010205 Content-Type: text/x-diff; name="0001-ob-gnuplot-temp-files-generated-only-once.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-ob-gnuplot-temp-files-generated-only-once.patch" >From 6e72396c6d5b280be900676fdcddcb14cdaf2f60 Mon Sep 17 00:00:00 2001 From: Thierry Banel Date: Tue, 3 Jan 2017 22:24:07 +0100 Subject: [PATCH] ob-gnuplot: temp files generated only once * lisp/ob-gnuplot.el (org-babel-gnuplot-process-vars): still called multiple times but caches temporary files generation --- lisp/ob-gnuplot.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lisp/ob-gnuplot.el b/lisp/ob-gnuplot.el index e91e05a..76d47fd 100644 --- a/lisp/ob-gnuplot.el +++ b/lisp/ob-gnuplot.el @@ -84,15 +84,17 @@ code." (lambda (pair) (cons (car pair) ;; variable name - (let* ((val (cdr pair)) ;; variable value - (lp (listp val))) - (if lp + (let ((val (cdr pair))) ;; variable value + (if (not (listp val)) + val + (let ((temp-file (org-babel-temp-file "gnuplot-")) + (first (car val))) + (setcdr pair temp-file) ;; <------ caching here (org-babel-gnuplot-table-to-data - (let* ((first (car val)) - (tablep (or (listp first) (symbolp first)))) - (if tablep val (mapcar 'list val))) - (org-babel-temp-file "gnuplot-") params) - val)))) + (if (or (listp first) (symbolp first)) + val + (mapcar 'list val)) + temp-file params)))))) (org-babel--get-vars params)))) (defun org-babel-expand-body:gnuplot (body params) -- 2.1.4 --------------030103060300010908010205--