Subject: bug#18522: 24.4.50; mapcar is very slow

From: Peter Münster <[email-masked]>
Date: Wed, 01 Oct 2014 21:55:21 +0200

On Fri, Sep 26 2014, Eli Zaretskii wrote:

> I think the conclusion is that parse-time-string takes the blame.  To
> see what part in parse-time-string is the culprit, perhaps load
> parse-time.el (the source) before the experiment, and maybe the
> profile will show more useful info.

This is the result:

--8<---------------cut here---------------start------------->8---
- command-execute                                                3228  94%
 - call-interactively                                            3228  94%
  - funcall-interactively                                        3150  92%
   - gnus-group-select-group                                     3142  92%
    - gnus-group-read-group                                      3142  92%
     - gnus-summary-read-group                                   3142  92%
      - gnus-summary-read-group-1                                3142  92%
       - gnus-summary-prepare                                    2772  81%
        - gnus-sort-threads                                      2657  78%
         - byte-code                                             2657  78%
          - gnus-sort-threads-recursive                          2657  78%
           - sort                                                2649  77%
            - #<compiled 0x16237ad>                              2649  77%
             - gnus-thread-sort-by-most-recent-date               2648  77%
              - gnus-thread-latest-date                          2648  77%
               - mapcar                                          2647  77%
                - #<compiled 0x8d9233>                           2645  77%
                 - safe-date-to-time                             2641  77%
                  - date-to-time                                 2641  77%
                   - byte-code                                   2641  77%
                    - parse-time-string                          2638  77%
                     - let                                       2637  77%
                      - parse-time-tokenize                      2613  76%
                       - let                                     2612  76%
                        - while                                  2612  76%
                         - while                                 2605  76%
                          - and                                  2602  76%
                           - setq                                1719  50%
                            - parse-time-string-chars               1712  50%
                             - save-match-data                   1697  49%
                              - let                              1689  49%
                               - unwind-protect                  1680  49%
                                - progn                          1675  49%
                                 - let                             26   0%
                                  - cond                           19   0%
                                     string-match                   1   0%
                           - not                                  876  25%
                            - setq                                875  25%
                             - parse-time-string-chars                874  25%
                              - save-match-data                   870  25%
                               - let                              868  25%
                                - unwind-protect                  865  25%
                                 - progn                          861  25%
                                  - let                            22   0%
                                   - cond                          22   0%
                                    - string-match                  4   0%
                                       setq                         4   0%
                                   set-match-data                   1   0%
                           - <                                      2   0%
                              setq                                  1   0%
                            setq                                    1   0%
                         - if                                       4   0%
                          - setq                                    4   0%
                           - cons                                   2   0%
                            - if                                    2   0%
                             - parse-integer                        1   0%
                              - let                                 1   0%
                               - if                                 1   0%
                                - progn                             1   0%
                                   let                              1   0%
                      - while                                      24   0%
                       - let                                       24   0%
                        - while                                    23   0%
                         - let*                                    20   0%
                          - if                                     13   0%
                           - progn                                  7   0%
                            - while                                 6   0%
                             - let                                  6   0%
                              - if                                  6   0%
                               - let                                6   0%
                                - if                                5   0%
                                 - parse-integer                    5   0%
                                  - let                             4   0%
                                   - if                             4   0%
                                    - progn                         3   0%
                                     - let                          3   0%
                                      - while                       1   0%
                                         and                        1   0%
                                        if                          1   0%
                                - car-safe                          1   0%
                                 - prog1                            1   0%
                                    setq                            1   0%
                           - and                                    6   0%
                            - setq                                  5   0%
                             - cond                                 5   0%
                              - and                                 2   0%
                               - not                                1   0%
                                  eq                                1   0%
                                 <=                                 1   0%
                                cdr                                 1   0%
                                funcall                             1   0%
                          - car-safe                                6   0%
                           - prog1                                  3   0%
                              setq                                  2   0%
                           and                                      1   0%
                          car-safe                                  1   0%
                      apply                                         3   0%
               - message-flatten-list                               1   0%
                  apply                                             1   0%
           - mapcar                                                 7   0%
            - #<compiled 0x8d7e39>                                  7   0%
             - gnus-sort-subthreads-recursive                       7   0%
              - mapcar                                              4   0%
               - #<compiled 0x8d8185>                               4   0%
                - gnus-sort-subthreads-recursive                    4   0%
                 - mapcar                                           4   0%
                  - #<compiled 0x8d8185>                            3   0%
                   - gnus-sort-subthreads-recursive                  3   0%
                    - sort                                          3   0%
                     - #<compiled 0x16237ad>                        3   0%
                      - gnus-thread-sort-by-most-recent-date                  3   0%
                       - gnus-thread-latest-date                    3   0%
                        - mapcar                                    3   0%
                         - #<compiled 0x8d9233>                     3   0%
                          - safe-date-to-time                       3   0%
                           - date-to-time                           3   0%
                            - byte-code                             3   0%
                             - parse-time-string                    2   0%
                              - let                                 2   0%
                               - parse-time-tokenize                  2   0%
                                - let                               2   0%
                                 - while                            2   0%
                                    while                           1   0%
                               apply                                1   0%
              - sort                                                3   0%
               - #<compiled 0x16237ad>                              3   0%
                - gnus-thread-sort-by-most-recent-date                  3   0%
                 - gnus-thread-latest-date                          3   0%
                  - mapcar                                          3   0%
                   - #<compiled 0x8d9233>                           3   0%
                    - safe-date-to-time                             3   0%
                     - date-to-time                                 3   0%
                      - byte-code                                   3   0%
                         apply                                      2   0%
                       - parse-time-string                          1   0%
                        - let                                       1   0%
                         - while                                    1   0%
                          - let                                     1   0%
                             while                                  1   0%
        - gnus-summary-prepare-threads                             97   2%
         - eval                                                    88   2%
          - let                                                    88   2%
           - gnus-add-text-properties                              85   2%
            - progn                                                84   2%
             - insert                                              82   2%
              - format                                             80   2%
               - let*                                              54   1%
                - eval                                             54   1%
                 - let                                             54   1%
                  - eval                                           51   1%
                   - gnus-summary-from-or-to-or-newsgroups                 50   1%
                    - mail-decode-encoded-address-string                 49   1%
                     - rfc2047-decode-string                       35   1%
                      - rfc2047-decode-encoded-words                 16   0%
                       - byte-code                                 16   0%
                        - quoted-printable-decode-string                 16   0%
                           generate-new-buffer                      5   0%
                         - byte-code                                3   0%
                          - kill-buffer                             1   0%
                           - replace-buffer-in-windows                  1   0%
                              unrecord-window-buffer                  1   0%
                           mm-disable-multibyte                     2   0%
                           quoted-printable-decode-region                  1   0%
                        generate-new-buffer                         7   0%
                      - byte-code                                   6   0%
                         kill-buffer                                4   0%
                        rfc2047-strip-backslashes-in-quoted-strings                  2   0%
                      bidi-string-mark-left-to-right                  1   0%
                  - if                                              2   0%
                     if                                             1   0%
                     >                                              1   0%
               - gnus-user-date                                    23   0%
                - byte-code                                        21   0%
                 - eval                                            17   0%
                    gnus-seconds-year                               8   0%
                    gnus-seconds-today                              6   0%
                  - +                                               2   0%
                     gnus-seconds-today                             1   0%
                 gnus-summary-line-message-size                     3   0%
            - cons                                                  1   0%
               cons                                                 1   0%
         - gnus-summary-highlight-line                              3   0%
            gnus-put-text-property-excluding-characters-with-faces                  1   0%
        - gnus-gather-threads-by-references                         9   0%
         - mail-header-remove-comments                              8   0%
          - byte-code                                               5   0%
           - kill-buffer                                            2   0%
            - replace-buffer-in-windows                             1   0%
               unrecord-window-buffer                               1   0%
            generate-new-buffer                                     3   0%
        - gnus-make-threads                                         1   0%
         - mapatoms                                                 1   0%
          - #<compiled 0x8d6107>                                    1   0%
           - mapcar                                                 1   0%
              #<compiled 0x8d60e3>                                  1   0%
       - gnus-select-newsgroup                                    366  10%
        - gnus-fetch-headers                                      363  10%
         - gnus-get-newsgroup-headers-xover                       362  10%
          - byte-code                                             354  10%
           - byte-code                                            292   8%
            - mail-decode-encoded-address-string                  203   5%
             - rfc2047-decode-string                              141   4%
              - rfc2047-decode-encoded-words                      105   3%
               - byte-code                                         97   2%
                - quoted-printable-decode-string                   86   2%
                   generate-new-buffer                             19   0%
                 - byte-code                                       19   0%
                  - kill-buffer                                     2   0%
                     replace-buffer-in-windows                      1   0%
                   mm-disable-multibyte                            16   0%
                   quoted-printable-decode-region                   1   0%
               - rfc2047-charset-to-coding-system                   7   0%
                - mm-charset-to-coding-system                       3   0%
                   mm-coding-system-p                               2   0%
                generate-new-buffer                                16   0%
              - byte-code                                          13   0%
               - kill-buffer                                        4   0%
                - replace-buffer-in-windows                         2   0%
                   unrecord-window-buffer                           2   0%
              - rfc2047-strip-backslashes-in-quoted-strings                  2   0%
               - byte-code                                          2   0%
                  forward-sexp                                      2   0%
            - mail-decode-encoded-word-string                      58   1%
             - rfc2047-decode-encoded-words                        44   1%
              - byte-code                                          43   1%
               - quoted-printable-decode-string                    40   1%
                  mm-disable-multibyte                              7   0%
                - byte-code                                         5   0%
                 - kill-buffer                                      1   0%
                    replace-buffer-in-windows                       1   0%
                  generate-new-buffer                               4   0%
             - byte-code                                            7   0%
              - kill-buffer                                         1   0%
               - replace-buffer-in-windows                          1   0%
                  unrecord-window-buffer                            1   0%
               generate-new-buffer                                  2   0%
           - mail-header-remove-comments                           33   0%
              generate-new-buffer                                  21   0%
            - byte-code                                            12   0%
             - kill-buffer                                          4   0%
              - replace-buffer-in-windows                           2   0%
                 unrecord-window-buffer                             1   0%
         - gnus-retrieve-headers                                    1   0%
          - gnus-cache-retrieve-headers                             1   0%
           - gnus-retrieve-headers                                  1   0%
            - nnml-retrieve-headers                                 1   0%
             - nnml-retrieve-headers-with-nov                       1   0%
              - nnheader-insert-file-contents                       1   0%
                 mm-insert-file-contents                            1   0%
        - gnus-summary-setup-default-charset                        1   0%
           gnus-parameter-charset                                   1   0%
        - gnus-article-setup-buffer                                 1   0%
           gnus-get-buffer-create                                   1   0%
       - gnus-group-decoded-name                                    1   0%
          gnus-group-name-decode                                    1   0%
       - gnus-summary-setup-buffer                                  1   0%
        - gnus-summary-mode                                         1   0%
         - gnus-update-summary-mark-positions                       1   0%
            gnus-summary-insert-line                                1   0%
       - gnus-run-hooks                                             1   0%
        - apply                                                     1   0%
         - run-hooks                                                1   0%
          - gnus-apply-kill-file                                    1   0%
             gnus-newsgroup-kill-file                               1   0%
   - execute-extended-command                                       8   0%
    - command-execute                                               6   0%
     - call-interactively                                           6   0%
      - funcall-interactively                                       6   0%
       - profiler-report                                            6   0%
        - profiler-report-cpu                                       6   0%
           profiler-cpu-profile                                     6   0%
  - byte-code                                                      78   2%
   - read-extended-command                                         78   2%
    - completing-read                                              78   2%
     - completing-read-default                                     78   2%
      - read-from-minibuffer                                       66   1%
       - redisplay_internal (C function)                            1   0%
          menu-bar-update-buffers                                   1   0%
       - timer-event-handler                                        1   0%
        - timer-activate-when-idle                                  1   0%
         - timer--activate                                          1   0%
            timer--time-less-p                                      1   0%
+ ...                                                             167   4%
+ timer-event-handler                                               6   0%
  redisplay_internal (C function)                                   1   0%
--8<---------------cut here---------------end--------------->8---

Is "progn" the problem?

What do you think?

-- 
           Peter