all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tomas Hlavaty <tom@logand.com>
To: Psionic K <psionik@positron.solutions>, help-gnu-emacs@gnu.org
Cc: incal@dataswamp.org, Eli Zaretskii <eliz@gnu.org>
Subject: Re: Identifying sources of allocations in a toy Mandelbrot package
Date: Fri, 19 Jan 2024 16:33:44 +0100	[thread overview]
Message-ID: <87v87ps5gn.fsf@neko.mail-host-address-is-not-set> (raw)
In-Reply-To: <CADQMGARbRmyjPP-6qdfki4utmUkUkwkzsmy8Z6EXPtOpW4i0KA@mail.gmail.com>

in lisp, a rough heuristic is that anything can allocate memory anytime

another useful heuristic is not to do things that do not need to be
done (not lisp-specific)

>> You have a pretty big vector
>
> The vector is allocated once and not on the same scale as usage,
> measured by profiling or by resident memory in top.

it does not need to be allocated at all

>     (eval-when-compile (require 'cl-lib))

have you tried eliminating cl-lib?

>         (let* ((cx) (cy) (zr) (zi) (v) (out) (zrt)
                 ^
                 those parens are unnecessary

also it is ugly to (let (a) (setq a 42) ...)

it is nice to put let around as little forms as possible
then the binding dependencies look clearer
and lack of setf and setq means
I don't have to think unnecessarily about sideeffects

>                (output (make-vector (* w h 3) 0))

you dont need the output vector at all, you already have an output
buffer so just write there directly

>               (setf cx (+ x0 (* dxp x)))

use let instead of setf and setq, everywhere

>                         (if (> (+ (* zr zr) (* zi zi)) 4) (cl-return v)

avoid cl-return

>               (aset output idx out)
>               (aset output (+ idx 1) out)
>               (aset output (+ idx 2) out)

insert the value into the output buffer here



  reply	other threads:[~2024-01-19 15:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19  9:19 Identifying sources of allocations in a toy Mandelbrot package Psionic K
2024-01-19 15:33 ` Tomas Hlavaty [this message]
2024-01-20  3:14   ` Psionic K
2024-01-20  3:37     ` Psionic K
2024-01-20  7:29     ` Eli Zaretskii
2024-01-20  9:09     ` Tomas Hlavaty
2024-01-20 10:03       ` Psionic K
2024-01-20 10:31         ` Eli Zaretskii
2024-01-26 23:36         ` Tomas Hlavaty
2024-01-27  1:07           ` Psionic K
2024-01-19 15:44 ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2024-01-27  9:25 Psionic K
2024-01-17 12:39 Psionic K
2024-01-17 12:58 ` Eli Zaretskii
2024-01-17 13:25 ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v87ps5gn.fsf@neko.mail-host-address-is-not-set \
    --to=tom@logand.com \
    --cc=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=incal@dataswamp.org \
    --cc=psionik@positron.solutions \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.