GNU bug report logs - #57197
28.1.90; Can pure side-effect-free functions use multiple CPUs in Elisp?

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Ihor Radchenko <yantar92@HIDDEN>; dated Sun, 14 Aug 2022 04:19:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 57197 <at> debbugs.gnu.org:


Received: (at 57197) by debbugs.gnu.org; 15 Aug 2022 07:13:52 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Aug 15 03:13:52 2022
Received: from localhost ([127.0.0.1]:40539 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1oNUIK-0005cs-Gz
	for submit <at> debbugs.gnu.org; Mon, 15 Aug 2022 03:13:52 -0400
Received: from quimby.gnus.org ([95.216.78.240]:56176)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1oNUII-0005ce-1w
 for 57197 <at> debbugs.gnu.org; Mon, 15 Aug 2022 03:13:50 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:Date:References:
 In-Reply-To:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=Z2iS59rb9tOdTryqFMcox4ABJyizmZVCv5QuW3hohPA=; b=r5OMEpZ02vsKDnmoYmrx44quXk
 8VuJeP4woiVIKbwTf5ggDVjIGxn6JaaDJ14FnzhrevqILwAMi63Rn/TZa0iJlND6H6jRWTPdQVuj8
 5IFjrQXPRU3dW8JdBtF7RF0zGJ4WZcwhy2Q+yf8eMgiBax8/k/fngysyJH9lmJ5ctRKE=;
Received: from [84.212.220.105] (helo=joga)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1oNUIA-0004pv-3v; Mon, 15 Aug 2022 09:13:44 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Akib Azmain Turja <akib@HIDDEN>
Subject: Re: bug#57197: 28.1.90; Can pure side-effect-free functions use
 multiple CPUs in Elisp?
In-Reply-To: <87a68659ro.fsf@HIDDEN> (Akib Azmain Turja's message of
 "Mon, 15 Aug 2022 11:57:31 +0600")
References: <875yiv1mqb.fsf@localhost> <87a68659ro.fsf@HIDDEN>
X-Now-Playing: Aksak Maboul's _Un Peu De L'Ame Des Bandits_: "Cinema"
Date: Mon, 15 Aug 2022 09:13:41 +0200
Message-ID: <87fshyasii.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview:  Akib Azmain Turja <akib@HIDDEN> writes: > I think the
 problem is the interpreter itself, which is not thread-safe. Yes,
 the interpreter
 (byte-code or not) itself is not thread-safe, so I don't think it's feasible
 to do anything here without a serious rewrite of that. 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 57197
Cc: yantar92@HIDDEN, 57197 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Akib Azmain Turja <akib@HIDDEN> writes:

> I think the problem is the interpreter itself, which is not thread-safe.

Yes, the interpreter (byte-code or not) itself is not thread-safe, so I
don't think it's feasible to do anything here without a serious rewrite
of that.





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#57197; Package emacs. Full text available.

Message received at 57197 <at> debbugs.gnu.org:


Received: (at 57197) by debbugs.gnu.org; 15 Aug 2022 05:58:24 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Aug 15 01:58:24 2022
Received: from localhost ([127.0.0.1]:40375 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1oNT7I-0005U1-8d
	for submit <at> debbugs.gnu.org; Mon, 15 Aug 2022 01:58:24 -0400
Received: from knopi.disroot.org ([178.21.23.139]:45354)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <akib@HIDDEN>) id 1oNT7G-0005Tr-Jf
 for 57197 <at> debbugs.gnu.org; Mon, 15 Aug 2022 01:58:23 -0400
Received: from localhost (localhost [127.0.0.1])
 by disroot.org (Postfix) with ESMTP id 3C77940076;
 Mon, 15 Aug 2022 07:58:21 +0200 (CEST)
X-Virus-Scanned: SPAM Filter at disroot.org
Received: from knopi.disroot.org ([127.0.0.1])
 by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id a_2jzaIxc-5I; Mon, 15 Aug 2022 07:58:20 +0200 (CEST)
From: Akib Azmain Turja <akib@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail;
 t=1660543098; bh=z96v9pDV2Q/7WuCdHqJXzbaUUNUn5VdPWT6U9sg0Tas=;
 h=From:To:Subject:In-Reply-To:Date;
 b=QBwMzDcTDfy3gsz75mznpaqRrKPPzIxqi+9qGxttAyWm7tUPfqClBn6TeSDw3/44A
 wr3gUi1eqqLmUN5ToecMTMWZDn00bCln4/xban7m1gll6/Itr592P5dOgW0iisfNUi
 NRZik6YZjZYrENkaAs8E9TJoCxcw8Pm0clqDcJB+wZeIInnCdySGCEvQZW+6NYCMmA
 TS4bdmh8/9nBOdbyqHDUPLlfOVX1sVF4OC6KaZUWqV8nsP41zBhe65Jg3iYLnVAh/A
 QytfaiLYp7zY2oZn8vtC/Xup6zl1Mtx6+cu1j7onitg5OIDAzYdB4YcU4l5LFgUuG4
 QddJXxFbjQEfg==
To: yantar92@HIDDEN, 57197 <at> debbugs.gnu.org
Subject: bug#57197: 28.1.90; Can pure side-effect-free functions use
 multiple CPUs in Elisp?
In-Reply-To: <875yiv1mqb.fsf@localhost>
Date: Mon, 15 Aug 2022 11:57:31 +0600
Message-ID: <87a68659ro.fsf@HIDDEN>
Mime-Version: 1.0
Content-Type: multipart/signed; boundary="=-=-=";
 micalg=pgp-sha256; protocol="application/pgp-signature"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 57197
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable


> Hi,
>=20
> The known blocker of Elisp support of multi-threading is shared Elisp
> machine state. Handling competing access to global Elisp variables is
> tricky. However, it is not the case for pure side-effect-free functions.
>=20
> Consider the following code:
>=20
> (let (long-list-of-cons)
>   (dotimes (i 100000)
>     (push (cons i (1+ i)) long-list-of-cons))
>   (mapcar #'car long-list-of-cons))
>=20
> The last mapcar looks like a good candidate to run on multiple CPUs.
> I imagine that instead of applying #'car sequentially, Elisp can split
> the list in chunks and run them independently on multiple CPUs. This
> operation is still blocking and thus will not create issues with shared
> access. At the same time such mapcar call will finish much faster.
>=20
> Would something like this be feasible to implement in Elisp?
>=20
> --=20
> Ihor Radchenko,
> Org mode contributor,
> Learn more about Org mode at https://orgmode.org/.
> Support Org development at https://liberapay.com/org-mode,
> or support my work at https://liberapay.com/yantar92
>

I think the problem is the interpreter itself, which is not thread-safe.
This looks like a feature request, I think emacs-devel is good for that.

=2D-=20
Akib Azmain Turja

Find me on Mastodon at @akib@HIDDEN

This message is signed by me with my GnuPG key.  Its fingerprint is:

    7001 8CE5 819F 17A3 BBA6  66AF E74F 0EFA 922A E7F5

--=-=-=
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEyVTKmrtL6kNBe3FRVTX89U2IYWsFAmL54EsACgkQVTX89U2I
YWvGZw//WPsraF/2R/QzEidQtg2oKzJbPeGyIS8hEJZsrMWUaqH/0QRXC/6cJavJ
LTL7mOF/9TzdtaEo1YJrjEsmK4DqTrmjyHOHSAdnjcpN82G/wBmQFBP63SuMTKDr
9f4vDQzXhrlyFhQkOtWvMN79zftppcOsaVrMAmDchfEjPbHGSjfM4tWHFUVWtE6S
KFs+U5i0Rdfo4Qrl5TvHBvPVV7fO/vrlmNZpnXZJItQHNQm87CIbuDHQrOlWEchG
mxDBbHshP/4tEPUCn/raFxB0VLAAK7YAXYbMylsZ8o36i7gwIxSWtPBtZ0SVGb2R
Ypq5UZL6d1rLpMnWm1LusY2RLr6MoWwj5/rFoGEtL7hEZpSbsl5kye755/9Po3op
zk2/3/+E8j1mzFFVZJNUYWlKcSXTUhnnvf5Kol3w7n/jU2vm6pH/5t3try2nCzrF
QL+oEuoRLdnvbT6EJ6NPTbGMKkOIwQ9RpgdFdao8ZJoY7bK8bCWrHhSNhhnqBgK0
xf3MPVNRFaNn9NjpLG257ZkL+YcGzn5+QOaiwYAGvyWddYSybFaHRP+Zg2egLGZT
H6kgS+Y8TyRtnaT0pxEFs4uCsSecYJosKc3QeMuSMjqHA1urrw/f9OthQhW7ECtX
HP7NsNg6IXf5vqgkMXGNMqjvftWmOTPG1b8gcbvZqBwu/GeD1OY=
=VNDT
-----END PGP SIGNATURE-----
--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#57197; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 14 Aug 2022 04:18:05 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Aug 14 00:18:05 2022
Received: from localhost ([127.0.0.1]:35581 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1oN54f-0004GB-DE
	for submit <at> debbugs.gnu.org; Sun, 14 Aug 2022 00:18:05 -0400
Received: from lists.gnu.org ([209.51.188.17]:58864)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <yantar92@HIDDEN>) id 1oN54d-0004G3-0X
 for submit <at> debbugs.gnu.org; Sun, 14 Aug 2022 00:18:03 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:35448)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <yantar92@HIDDEN>)
 id 1oN54c-00032G-2F
 for bug-gnu-emacs@HIDDEN; Sun, 14 Aug 2022 00:18:02 -0400
Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:37541)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <yantar92@HIDDEN>)
 id 1oN54T-0002Ip-JK
 for bug-gnu-emacs@HIDDEN; Sun, 14 Aug 2022 00:18:01 -0400
Received: by mail-pl1-x635.google.com with SMTP id m2so3880617pls.4
 for <bug-gnu-emacs@HIDDEN>; Sat, 13 Aug 2022 21:17:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=mime-version:message-id:date:subject:to:from:from:to:cc;
 bh=RpdT/2qyRGTy3BgJjjIzRavyiRZCnoNgqHl7sxvPo6Y=;
 b=hvo8qY9JZX/JhxekxTXuJFBiF4A6ZFlYL/BBLFZM8TMgLNgTPENB2Qq4TSdevTKgiw
 dy6AJhfYofsu8nJyQqSTt9bhBMXQBFBIzk7yaNVaoxc/3qYkXvuPuBsBJXOAA7BgBDjr
 QRkVLYUfDJTaNJ1WI2/3IplSQItbmxhiIHEV0OOj+EL6903oRwa3MQssF0+5bzR0QD1z
 0d/Aa2mjWpfIH65isDeW+yPLMnlEHTg4t/3yTUcci87RUMDU5VrtL0sPyfbNP/PVKlFD
 CM58cIRzn1sUWZY7YCDFMFIPt/hvFHaEoOdMTmuRJH/glSomO1GaJIDjm0y4bNtCNeEt
 WwSQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=mime-version:message-id:date:subject:to:from:x-gm-message-state
 :from:to:cc;
 bh=RpdT/2qyRGTy3BgJjjIzRavyiRZCnoNgqHl7sxvPo6Y=;
 b=D4bJ6XNirsGoaWmcWLYEsWDLsgonutAjMIx1NTxhR7KvJOya5z6hF3FES/dMXO4bi7
 OOXA6mOaFuI0BKcrLX3/68/iGVosaf0mdz3KQuOiYrmYzQLp2zUbweeeqRhUOuCxdnZX
 XLjSVTlx+7goAxSFYU2VQ5LZ94j9nrQqOczBzifUL8PZGXOBTq3SJk8mI7zZzgbTHZDZ
 69dSyfr9UqdIGrmkUhxLCmZHNyBjs8AZNkQveof25nRg4Vhr4oUJUS4DTBFxPj64zc6/
 w1yV5IMIwAhY1Nrn/UZT64PUOgoJ1LBLfeEOFeeSP0EMubqrJEiWgHICnDYjwjjs0uuj
 5x9g==
X-Gm-Message-State: ACgBeo2QrY290QofHWCZshvMR4J4w5HFqltDahg+waFFjNHUbHsUFfvQ
 QnOESLswcBBk0Zm5coCXcJJ6LGOROB5zCQ==
X-Google-Smtp-Source: AA6agR7DMZZwetzn6e6STq63Y95uYipnwswznjP0TBs9y3FBerdf2ohaa2L6xy0DkiSmWnrNAKsWlw==
X-Received: by 2002:a17:902:7883:b0:170:d646:7f00 with SMTP id
 q3-20020a170902788300b00170d6467f00mr11151062pll.164.1660450671466; 
 Sat, 13 Aug 2022 21:17:51 -0700 (PDT)
Received: from localhost ([2409:8a70:2bf:80b0:8ec6:81ff:fe70:339d])
 by smtp.gmail.com with ESMTPSA id
 r15-20020aa7988f000000b0052d51acf115sm4366341pfl.157.2022.08.13.21.17.49
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 13 Aug 2022 21:17:50 -0700 (PDT)
From: Ihor Radchenko <yantar92@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 28.1.90; Can pure side-effect-free functions use multiple CPUs in
 Elisp?
Date: Sun, 14 Aug 2022 12:18:52 +0800
Message-ID: <875yiv1mqb.fsf@localhost>
MIME-Version: 1.0
Content-Type: text/plain
Received-SPF: pass client-ip=2607:f8b0:4864:20::635;
 envelope-from=yantar92@HIDDEN; helo=mail-pl1-x635.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-Spam-Score: -1.1 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.1 (--)

Hi,

The known blocker of Elisp support of multi-threading is shared Elisp
machine state. Handling competing access to global Elisp variables is
tricky. However, it is not the case for pure side-effect-free functions.

Consider the following code:

(let (long-list-of-cons)
  (dotimes (i 100000)
    (push (cons i (1+ i)) long-list-of-cons))
  (mapcar #'car long-list-of-cons))

The last mapcar looks like a good candidate to run on multiple CPUs.
I imagine that instead of applying #'car sequentially, Elisp can split
the list in chunks and run them independently on multiple CPUs. This
operation is still blocking and thus will not create issues with shared
access. At the same time such mapcar call will finish much faster.

Would something like this be feasible to implement in Elisp?

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92




Acknowledgement sent to Ihor Radchenko <yantar92@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#57197; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 15 Aug 2022 07:15:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.