emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [elpa] main 2ec80977e1: * elpa-packages (dired-preview): New package


From: Stefan Monnier
Subject: Re: [elpa] main 2ec80977e1: * elpa-packages (dired-preview): New package
Date: Tue, 11 Jul 2023 09:33:14 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

>> I saw 'rx' a couple of times.  I find it harder to use than the strings.
>> Though this is not a strong argument against it, I know.
>
> In this case, it would be
>
> --8<---------------cut here---------------start------------->8---
> (rx "." (or "mkv" "webm" "mp4" "mp3" "ogg" "m4a"
>           "gz" "zst" "tar" "xz" "rar" "zip"
>           "iso" "epub" "pdf"))
> --8<---------------cut here---------------end--------------->8---
>
> which seems fine to me?  Fewer escape-sequences.
>
>>>            "\\(mkv\\|webm\\|mp4\\|mp3\\|ogg\\|m4a"
>>>            "\\|gz\\|zst\\|tar\\|xz\\|rar\\|zip"
>>>            "\\|iso\\|epub\\|pdf\\)")
>>>    "Regular expression of file type extensions to not preview."
>>> -  :group 'dired-preview
>>>    :type 'string)

BTW, you can most of the benefit here by using `regexp-opt` instead:

    (concat "\\."
            (regexp-opt "mkv" "webm" "mp4" "mp3" "ogg" "m4a"
                        "gz" "zst" "tar" "xz" "rar" "zip"
                        "iso" "epub" "pdf"))

> So unless you can make use of η-reduction, mapc incurs an overhead of
> a funcall overhead for each element, but had an advantage in that
> iteration happens in-core.

For the specific case at hand, there's also the cost of allocating the
closure and converting the free variable into a cons-cell (because it's
modified) which slows down accesses to it.  IOW

    (let ((size 0))
      (mapc
       (lambda (buffer)
         (setq size (+ (buffer-size buffer) size)))
       (dired-preview--get-buffers))
      size))

will look somewhat like:

    (let ((size (list 0)))
      (mapc
       (make-closure
         (lambda (buffer)
           (setcar V0 (+ (buffer-size buffer) (car V0))))
         size)
       (dired-preview--get-buffers))
      (car size))

See bytecode below.


        Stefan


byte code:
  args: nil
0       constant  0
1       list1     
2       constant  mapc
3       constant  make-closure
4       constant  <compiled-function>
      doc:   ...
      args: (arg1)
    0       constant  V0
    1       constant  buffer-size
    2       stack-ref 2
    3       call      1
    4       constant  V0
    5       car-safe  
    6       plus      
    7       setcar    
    8       return    

5       stack-ref 3
6       call      2
7       constant  dired-preview--get-buffers
8       call      0
9       call      2
10      discard   
11      car-safe  
12      return    




reply via email to

[Prev in Thread] Current Thread [Next in Thread]