From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: [External] : Passing buffers to function in elisp Date: Tue, 28 Feb 2023 06:37:32 +0100 Message-ID: References: <87mt56hg4e.fsf@iki.fi> <87bklihln8.fsf@iki.fi> <87pm9yf0ph.fsf@web.de> <87v8jmkfd0.fsf@iki.fi> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="O4PlZeVkAYt1ZeWy" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33164"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Feb 28 06:38:20 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWsgs-0008Pu-Ht for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 28 Feb 2023 06:38:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pWsgE-0004io-Hx; Tue, 28 Feb 2023 00:37:38 -0500 Original-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 1pWsgC-0004iO-E0 for help-gnu-emacs@gnu.org; Tue, 28 Feb 2023 00:37:36 -0500 Original-Received: from mail.tuxteam.de ([5.199.139.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pWsgA-0002P7-Jk for help-gnu-emacs@gnu.org; Tue, 28 Feb 2023 00:37:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:Date:Sender:Reply-To:Cc: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=OhQvkC2glQ3r+VXY4QVpf2Mh4hZa2hVUNYBch539u68=; b=LWVfpntUfap4fDq2zCWod/vd+a Y5sdJcRZckUJ5DyBgSB6Q+ojRra9Y0vzYWZEqTuXTcwriJLqvvoVDgLXezoPLbOVUfXVU+4XM3MQU PCBHXFmLvd1Ocj3nRU58sTcKK5vTVdHAgz0jUvVb6uMAwSeQ8z3xLRPsNIBUvul8sjUphUmMy/QkU efaWUQSXPbLdcI50EbTrR6MubbCDmbs05WMxNSsN6PXSzct5bIU4NZJcTtQqQXAbYTLRTMIMBnUBS 2PEA1kcP/rW/uTly7gdtae+IwLA6tsIF8X0n3DXl2IxLm+XL0oqMgYZwZKRKmASHjXnkqEdrvcSpW GFT5xnOQ==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1pWsg8-0001aJ-1L for help-gnu-emacs@gnu.org; Tue, 28 Feb 2023 06:37:32 +0100 Content-Disposition: inline In-Reply-To: <87v8jmkfd0.fsf@iki.fi> Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:142872 Archived-At: --O4PlZeVkAYt1ZeWy Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 27, 2023 at 10:44:43PM +0200, Petteri Hintsanen wrote: [...] > Also, if I interpreted profiler's hieroglyphs correctly, it told me that > this setq >=20 > (setq stream (vconcat stream (plist-get page :stream))) >=20 > is a pig -- well, of course it is. I'm accumulating byte vector by > copying its parts. Similarly bindat consumes a lot of memory. >=20 > I think I can replace vectors with strings, which should, according to > the elisp manual, "occupy one-fourth the space of a vector of the same > elements." And I guess that accumulation would be best done with a > buffer, not with strings or vectors. I must admit I didn't look too closely into your code, but this one stuck out too. Not only the copying, but the throwing away of so many vectors. I don't know whether it applies in your case, but one "classical" Lispy pattern when you have to concatenate many things in order is just consing them (at the front of the list) and nreversing the list at the end, like so: (let ((result '())) (while (more) (setq result (cons (next) result))) (nreverse result)) (nreverse does things "in place", so it reuses the cons pairs: never do that when someone else is looking ;-) Another, more functional, of course is to arrange things so you can use map or similar. Then, at the end you can concatenate the whole list, if need be. Basically it pays off when the "spine" of the whole thing (i.e. all those cons pairs you are using) is significantly smaller than whatever hangs off it Cheers --=20 t --O4PlZeVkAYt1ZeWy Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCY/2TFQAKCRAFyCz1etHa Rs9XAJ9vjxqt9kJh1eo/VhJ8OzQ0IakLeQCcCp5buK0KuLPORRWSVWi6aPxb10Q= =1TFG -----END PGP SIGNATURE----- --O4PlZeVkAYt1ZeWy--