unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: emacs-devel@gnu.org
Cc: Stefan Kangas <stefankangas@gmail.com>
Subject: Re: master 82cc1f4fda1: Revert use of seq-count in shr-count
Date: Mon, 04 Sep 2023 20:54:25 +0000	[thread overview]
Message-ID: <874jk97j7i.fsf@posteo.net> (raw)
In-Reply-To: <20230904193238.46053C04DB0@vcs2.savannah.gnu.org> (Stefan Kangas's message of "Mon, 4 Sep 2023 15:32:38 -0400 (EDT)")

Stefan Kangas <stefankangas@gmail.com> writes:

> branch: master
> commit 82cc1f4fda19a635cc29577a4da051cf3e062afe
> Author: Stefan Kangas <stefankangas@gmail.com>
> Commit: Stefan Kangas <stefankangas@gmail.com>
>
>     Revert use of seq-count in shr-count
>     
>     * lisp/net/shr.el (shr-count): Prefer handwritten code to using
>     'seq-count', as it's more performant.
>     Problem reported by Mattias Engdegård <mattiase@acm.org>.

With seq becoming more and more popular, is there any conceivable way of
making it faster as well?  The overhead of generic functional-call
dispatching always has me weary of using the library, or at the very
least has me think about it twice as it is convenient.  Is there some
way to use the type inference that native compilation appears to provide
to statically determine what implementation to use?

> ---
>  lisp/net/shr.el | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/lisp/net/shr.el b/lisp/net/shr.el
> index 84033c31ef4..645e1cc51e5 100644
> --- a/lisp/net/shr.el
> +++ b/lisp/net/shr.el
> @@ -2617,10 +2617,13 @@ flags that control whether to collect or render objects."
>      columns))
>  
>  (defun shr-count (dom elem)
> -  (seq-count (lambda (sub)
> -               (and (not (stringp sub))
> -                    (eq (dom-tag sub) elem)))
> -             (dom-children dom)))
> +  ;; This is faster than `seq-count', and shr can use it.
> +  (let ((i 0))
> +    (dolist (sub (dom-children dom))
> +      (when (and (not (stringp sub))
> +                 (eq (dom-tag sub) elem))
> +        (setq i (1+ i))))
> +    i))
>  
>  (defun shr-max-columns (dom)
>    (let ((max 0)



       reply	other threads:[~2023-09-04 20:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <169385595799.24305.652316651780689026@vcs2.savannah.gnu.org>
     [not found] ` <20230904193238.46053C04DB0@vcs2.savannah.gnu.org>
2023-09-04 20:54   ` Philip Kaludercic [this message]
2023-09-05  2:34     ` master 82cc1f4fda1: Revert use of seq-count in shr-count Eli Zaretskii
2023-09-06  0:02       ` Karthik Chikmagalur
2023-09-06 11:34         ` Eli Zaretskii
2023-09-06 12:34           ` Eli Zaretskii
2023-09-06 22:21             ` Philip Kaludercic

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=874jk97j7i.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=emacs-devel@gnu.org \
    --cc=stefankangas@gmail.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).