From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Psionic K Newsgroups: gmane.emacs.help Subject: Re: Identifying sources of allocations in a toy Mandelbrot package Date: Sat, 20 Jan 2024 12:14:53 +0900 Message-ID: References: <87v87ps5gn.fsf@neko.mail-host-address-is-not-set> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4749"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Psionic K , help-gnu-emacs@gnu.org, incal@dataswamp.org, Eli Zaretskii To: Tomas Hlavaty Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 20 04:15:57 2024 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 1rR1pt-00011K-4l for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 20 Jan 2024 04:15:57 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rR1pA-0003eA-NM; Fri, 19 Jan 2024 22:15:13 -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 1rR1p7-0003dv-BD for help-gnu-emacs@gnu.org; Fri, 19 Jan 2024 22:15:09 -0500 Original-Received: from mail-yb1-xb33.google.com ([2607:f8b0:4864:20::b33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rR1p5-0003dF-Ba for help-gnu-emacs@gnu.org; Fri, 19 Jan 2024 22:15:09 -0500 Original-Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-dc22ade26d8so1176695276.1 for ; Fri, 19 Jan 2024 19:15:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=positron.solutions; s=google; t=1705720504; x=1706325304; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=D9a03bZzzBnHmckRVks8MmFxDJ6pNWj+u2iU4AJGPiM=; b=DrJFgwLwxvjUl2tbqo3prTH7pPa7b9lZJg+MMnCWTIExUuVLyXMSv+jn6VpC720ZyY aBBgOsr8lIzrb4Ur2qmhI989IEqA8iVX0OJpGgfE2I320OXKoRAMSfzcO4iRFkZnEBCN /4R7Mvby6Z2KRNv15vSJJfaGtfN8s24j1vVi0w6A3+ZWdoEfnF0Ni1AGmK42mVhA7yl3 VZPjRAWYLjo6fAYphnDE45PeCox1A3xz0xqFFc/wJ2fUgoDUQFus7G+sivnTIuriItPg fPSwAxsOu2WIztcND78+dfGM5WlvuVpWCCbWnDgWuC/fRp6h1iOv+GFtRpIovHyXi4/E H1BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705720504; x=1706325304; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=D9a03bZzzBnHmckRVks8MmFxDJ6pNWj+u2iU4AJGPiM=; b=v/YuZ/q8ENC5gitc/ZOzsBf2YeMLP9UWr9c+Ch8+l3XZKpnDvtaGJjVTJzzAeM0eHJ 9ODp7Yz7B7h6LfAU77uN4HWie0P2cBYKnrbWckc+tIajEZlHU4KICicktZIU+I4wSlSP NNnaYxa4Icwp8pD0AgBqy285jtvrQOF2KzU5WW6mpfDwn4NTNsDMkC4nxsJ98YkLKWN+ cAquB1AmCQZmIlnyzSZ7brnTXfIQrd2ge+0ohKrvbdTleHefHiMcPSXHZ1APJ6E8iC32 FsmRM3IkO1dlHHU5g1mdwT8XWcfbdhmJolRMVGt86y3gGgDnR/H6SqfreuJgodKK2gjd vUyA== X-Gm-Message-State: AOJu0YyrHmJ/8GDNOsmoQD6nJf8pgL/gpmI3LIcsXbdfpWnZPPG3RxUP CUSA9PWHCsVAXkXuqq60CJlvSaesTynpiT2cLlXvEiIqKE5L3Q6hVzoQa3rvVWmIJplHqPvK5J6 XU60keQd8QSNE+4RhzrmLAGeYgoP9L6mNTDpviQ== X-Google-Smtp-Source: AGHT+IH5mh9/pldKhsc/lo07MvlcNpUEKC/U8A/I5IUXm9kdX7BMYli05sDmErcGF/8MJYZKe+tUoFcwKaTSArSBt8k= X-Received: by 2002:a0d:f8c1:0:b0:5ec:aaf8:39bd with SMTP id i184-20020a0df8c1000000b005ecaaf839bdmr747095ywf.36.1705720504554; Fri, 19 Jan 2024 19:15:04 -0800 (PST) In-Reply-To: <87v87ps5gn.fsf@neko.mail-host-address-is-not-set> Received-SPF: pass client-ip=2607:f8b0:4864:20::b33; envelope-from=exec@positron.solutions; helo=mail-yb1-xb33.google.com 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, HTML_MESSAGE=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-Content-Filtered-By: Mailman/MimeDel 2.1.29 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:145756 Archived-At: > Any temporary Lisp objects will allocate memory. Their references will be on the stack, but the objects themselves will be on the heap. I had presumed at a minimum that the compiler can re-use heap locations when it decides there's no risk. While the values will be in the heap, is there a way to destructively re-use heap locations so that we are not burning through all of the heap during iteration? Do function calls re-use any heap space? Does anything besides GC? As it is, I can guess that every call to even + or * is creating a unique float that now exists on the heap until GC'd. The vector would have a bounded size of about 50-100MB. To avoid us focusing on it, I have removed it. No material impact. > have you tried eliminating cl-lib? No change. After getting rid of cl-return, I'm doing worse, at around 16.0s and however much memory I provide. > use let instead of setf and setq, everywhere Without using recursion to change the iteration structure to one that never uses setq, I obtained a version that is consistent with all of the GC tradeoffs I've seen so far, requiring between 10 and 20 seconds depending on how much memory I allow. Should I consider further modifications? ;;; mandelbrot.el --- Mandelbrot -*- lexical-binding: t; -*- ;;; Commentary: ;; Render's Mandelbrot set. ;;; Code: ;;;###autoload (defun mandelbrot () "Render a Mandelbrot." (declare (speed 3)) (interactive) (pop-to-buffer (get-buffer-create "*Mandelbrot*")) (fundamental-mode) (erase-buffer) (set-buffer-multibyte nil) (let ((gc-cons-threshold (* 800000 1024)) (gc-cons-percentage 0.6) (inhibit-modification-hooks t) (w 1600) (h 1200) (d 256) (dd 256.0) (x0 -2.5) (y0 -1.5) (dx 4.0) (dy 3.0)) (insert (format "P6\n%d %d\n255\n" w h)) (let* ((dxp (/ dx w)) (dyp (/ dy h))) (dotimes (y h) (message "Row: %d" y) ; removal prevents GC (let ((cy (+ y0 (* dyp y)))) (dotimes (x w) (let ((cx (+ x0 (* dxp x))) (zr 0) (zi 0) (v 0) (not-escaped t)) (while (and not-escaped (< v d)) (if (> (+ (expt zr 2.0) (expt zi 2.0)) 4) (setq not-escaped nil) (let ((zrt (+ (* zr zr) (- (* zi zi)) cx))) (setq zi (+ (* (* zr zi) 2.0) cy)) (setq zr zrt)) (setq v (1+ v)))) ;; samples that hit 256 wrap in the graphic to display as zero ;; exponential 0.8 enhances contrast a bit (let ((out (floor (* 256 (/ v dd))))) (insert out out out)))))) (image-mode)))) (provide 'mandelbrot) ;;; mandelbrot.el ends here.