From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Petteri Hintsanen Newsgroups: gmane.emacs.help Subject: Re: [External] : Passing buffers to function in elisp Date: Tue, 07 Mar 2023 23:48:10 +0200 Message-ID: <87jzzsjkrp.fsf@iki.fi> References: <87mt56hg4e.fsf@iki.fi> <87bklihln8.fsf@iki.fi> <87pm9yf0ph.fsf@web.de> <87v8jmkfd0.fsf@iki.fi> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30323"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Cc: Stefan Monnier To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 07 22:48:57 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 1pZfB2-0007aH-Ti for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 07 Mar 2023 22:48:56 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZfAZ-0004Hq-Ta; Tue, 07 Mar 2023 16:48:28 -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 1pZfAY-0004HQ-Ni for help-gnu-emacs@gnu.org; Tue, 07 Mar 2023 16:48:26 -0500 Original-Received: from sirokuusama2.dnainternet.net ([83.102.40.153]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZfAW-0004o8-Gg for help-gnu-emacs@gnu.org; Tue, 07 Mar 2023 16:48:26 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by sirokuusama2.dnainternet.net (Postfix) with ESMTP id BAB601290E for ; Tue, 7 Mar 2023 23:48:12 +0200 (EET) X-Virus-Scanned: DNA Internet at dnainternet.net Original-Received: from sirokuusama2.dnainternet.net ([83.102.40.153]) by localhost (sirokuusama2.dnainternet.net [127.0.0.1]) (DNA Internet, port 10041) with ESMTP id fzZ4dEH0SL-C for ; Tue, 7 Mar 2023 23:48:12 +0200 (EET) Original-Received: from oliivipuu2.dnainternet.net (oliivipuu2.dnainternet.net [83.102.40.53]) by sirokuusama2.dnainternet.net (Postfix) with ESMTP id 901DC12830 for ; Tue, 7 Mar 2023 23:48:12 +0200 (EET) Original-Received: from romeo (62-78-178-196.bb.dnainternet.fi [62.78.178.196]) by oliivipuu2.dnainternet.net (Postfix) with ESMTP id 7F3B298 for ; Tue, 7 Mar 2023 23:48:10 +0200 (EET) Original-Received: from phintsan (uid 1000) (envelope-from petterih@iki.fi) id 50010b by romeo (DragonFly Mail Agent v0.13); Tue, 07 Mar 2023 23:48:10 +0200 In-Reply-To: (Stefan Monnier via Users list for the's message of "Fri, 03 Mar 2023 10:19:09 -0500") Received-SPF: neutral client-ip=83.102.40.153; envelope-from=petterih@iki.fi; helo=sirokuusama2.dnainternet.net X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, UNPARSEABLE_RELAY=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:142939 Archived-At: Stefan Monnier via Users list for the GNU Emacs text editor writes: > This is a typical a source of unnecessary O(N=C2=B2) complexity: the above > line takes O(N) time, so if you do it O(N) times, you got your > N=C2=B2 blowup. You're usually better off doing > > (push (plist-get page :stream) stream-chunks) > > and then at the end get the `stream` with > > (mapconcat #'identity (nreverse stream-chunks) nil) > or > (apply #'vconcat (nreverse stream-chunks)) Right, I see. Stream chunks are in this case byte vectors, so just reversing those chunks does not do the trick. But surely I can get from an order of N=C2=B2 to 2N or so. > Of course that depends on what else happens with `stream` (I haven't > really looked at your code, sorry). It's ok, I'm not expecting any reviews here. All these comments from you and others have been valuable already. >> No, it was not byte-compiled. > > Then stop right there and fix this problem. There's absolutely no point > worrying about performance (including memory use) if the code is > not compiled because compilation can change the behavior drastically. > > The only reason to run interpreted code nowadays is when you're > Edebugging a piece of code. Okay, this is something I did not foresee. But what about eval-defun and eval-... in general? They are very convenient when trying out things. Should I bind compile-defun to C-M-x then? And instead of eval-buffer use byte-compile-file? Or emacs-lisp-byte-compile-and-load? Manual is a bit spotty here; emacs-lisp-byte-compile-... functions are not mentioned. >> I'll try byte-compiling after the code is in good enough shape to do >> controlled experiments. > > The compiler is your friend. He can help you get the code in good shape = :-) I'm afraid that even the compiler cannot help against quadratic complexity blunders. But I think I got your point. Thanks, Petteri