~niklaseklund/detached.el

5 2

detached-init slowing down emacs startup

Details
Message ID
<54v8pfm2mq.fsf@olaptop-hp.mail-host-address-is-not-set>
DKIM signature
missing
Download raw message
Latest changes in handling initialization of sessions are slowing down emacs startup.

to reproduce:
  - running emacs with (detached-init) in init.el
  - running multiple commands with detached.el
  - exiting emacs
  - running emacs again

evaluating "(benchmark-run 1 (detached-init))":
 with 30 sessions  -> (1.160732093 1 0.025991540000000007)
 with 300 sessions -> (10.819843602 30 0.8100858790000001)

running the profiler:

memory:
    245,243,345  98%      - detached-init
    245,243,345  98%       - detached-init--detached
    245,243,345  98%        - eval-after-load
    245,243,345  98%         - #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_5>
    245,232,537  98%          - detached-initialize-sessions
    244,778,186  98%           - seq-do
    244,778,186  98%            - mapc
    244,778,186  98%             - detached--initialize-session
    244,777,122  98%              - detached--db-update-entry
      8,163,572   3%               - detached--db-update-sessions
      6,821,095   2%                - select-safe-coding-system
      6,817,603   2%                   find-auto-coding
         32,460   0%                  make-lock-file-name
          1,064   0%                seq-filter
        156,463   0%           + detached--db-initialize
         81,212   0%           + detached--register-detached-emacs
         48,883   0%           + detached--active-detached-emacsen
         30,301   0%           + detached--update-detached-emacsen

cpu:
        1374  59%      - detached-init
        1374  59%       - detached-init--detached
        1374  59%        - eval-after-load
        1374  59%         - #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_5>
        1374  59%          - detached-initialize-sessions
        1367  59%           - seq-do
        1367  59%            - mapc
        1366  59%             - detached--initialize-session
        1351  58%              - detached--db-update-entry
          60   2%               - detached--db-update-sessions
          49   2%                - select-safe-coding-system
          49   2%                   find-auto-coding
           8   0%                  make-lock-file-name
           3   0%                - #<compiled -0x1ddfd58fa087bdef>
           1   0%                   kill-buffer
           5   0%              + detached--session-missing-p
           1   0%              + seq-filter
           2   0%           + detached--db-initialize
           1   0%           + detached--active-detached-emacsen
        .......................
         799  34%    Automatic GC
Details
Message ID
<eruuehh70yjz9v.fsf@posteo.net>
In-Reply-To
<54v8pfm2mq.fsf@olaptop-hp.mail-host-address-is-not-set> (view parent)
DKIM signature
missing
Download raw message
Osama Rebach <osamarebach@gmail.com> writes:

Hi Osama,

> Latest changes in handling initialization of sessions are slowing down emacs startup.

thanks for reporting this issue.

> to reproduce:
>   - running emacs with (detached-init) in init.el
>   - running multiple commands with detached.el
>   - exiting emacs
>   - running emacs again
>
> evaluating "(benchmark-run 1 (detached-init))":
>  with 30 sessions  -> (1.160732093 1 0.025991540000000007)
>  with 300 sessions -> (10.819843602 30 0.8100858790000001)

Great that you provide these steps and benchmark results. I don't manage
to reproduce it locally today. But I did notice some slower
initialization the other day, not sure why I didn't today.

I have created a branch named init_speedup. Could you try that one out
and see if it improves the situation on your end.

This is the commit I made
https://git.sr.ht/~niklaseklund/detached.el/commit/8b224c78b8ef6cce02c06af1f7a3e7e23dbf2ccd

/Niklas

> running the profiler:
>
> memory:
>     245,243,345  98%      - detached-init
>     245,243,345  98%       - detached-init--detached
>     245,243,345  98%        - eval-after-load
>     245,243,345  98%         - #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_5>
>     245,232,537  98%          - detached-initialize-sessions
>     244,778,186  98%           - seq-do
>     244,778,186  98%            - mapc
>     244,778,186  98%             - detached--initialize-session
>     244,777,122  98%              - detached--db-update-entry
>       8,163,572   3%               - detached--db-update-sessions
>       6,821,095   2%                - select-safe-coding-system
>       6,817,603   2%                   find-auto-coding
>          32,460   0%                  make-lock-file-name
>           1,064   0%                seq-filter
>         156,463   0%           + detached--db-initialize
>          81,212   0%           + detached--register-detached-emacs
>          48,883   0%           + detached--active-detached-emacsen
>          30,301   0%           + detached--update-detached-emacsen
>
> cpu:
>         1374  59%      - detached-init
>         1374  59%       - detached-init--detached
>         1374  59%        - eval-after-load
>         1374  59%         - #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_5>
>         1374  59%          - detached-initialize-sessions
>         1367  59%           - seq-do
>         1367  59%            - mapc
>         1366  59%             - detached--initialize-session
>         1351  58%              - detached--db-update-entry
>           60   2%               - detached--db-update-sessions
>           49   2%                - select-safe-coding-system
>           49   2%                   find-auto-coding
>            8   0%                  make-lock-file-name
>            3   0%                - #<compiled -0x1ddfd58fa087bdef>
>            1   0%                   kill-buffer
>            5   0%              + detached--session-missing-p
>            1   0%              + seq-filter
>            2   0%           + detached--db-initialize
>            1   0%           + detached--active-detached-emacsen
>         .......................
>          799  34%    Automatic GC
Details
Message ID
<54o7v6o5ot.fsf@olaptop-hp.mail-host-address-is-not-set>
In-Reply-To
<eruuehh70yjz9v.fsf@posteo.net> (view parent)
DKIM signature
missing
Download raw message
Niklas Eklund <niklas.eklund@posteo.net> writes:

> Great that you provide these steps and benchmark results. I don't manage
> to reproduce it locally today. But I did notice some slower
> initialization the other day, not sure why I didn't today.

the slowdown happens for the first evaluation of (detached-init), after
that running (detached-init) runs quickly. so to reproduce it you need to
remove (detached-init) from the init file, and running it independently,
and exiting emacs every time. and rerun it again

> I have created a branch named init_speedup. Could you try that one out
> and see if it improves the situation on your end.

i will try it and report back.
Details
Message ID
<eruuehillesd3n.fsf@posteo.net>
In-Reply-To
<54o7v6o5ot.fsf@olaptop-hp.mail-host-address-is-not-set> (view parent)
DKIM signature
missing
Download raw message
Osama Rebach <osamarebach@gmail.com> writes:

> Niklas Eklund <niklas.eklund@posteo.net> writes:
>
>> Great that you provide these steps and benchmark results. I don't manage
>> to reproduce it locally today. But I did notice some slower
>> initialization the other day, not sure why I didn't today.
>
> the slowdown happens for the first evaluation of (detached-init), after
> that running (detached-init) runs quickly. so to reproduce it you need to
> remove (detached-init) from the init file, and running it independently,
> and exiting emacs every time. and rerun it again

I was doing that but for some reason it was fast anyway. I don't have
many sessions at the moment, forcefully created a lot of them for
testing purpose. I'll see if any slowdown occurs once I have built up
more organic sessions.

>> I have created a branch named init_speedup. Could you try that one out
>> and see if it improves the situation on your end.
>
> i will try it and report back.

Great! I added two more commits to the branch just for your information.
Details
Message ID
<54czbm7a5q.fsf@olaptop-hp.mail-host-address-is-not-set>
In-Reply-To
<eruuehh70yjz9v.fsf@posteo.net> (view parent)
DKIM signature
missing
Download raw message
Thanks, running the "init_speedup" branch resolved the issue.

Now running (detached-init) with 250 sessions:
  (0.17904190499999997 1 0.02780058099999999)
Details
Message ID
<eruuehfsgisc91.fsf@posteo.net>
In-Reply-To
<54czbm7a5q.fsf@olaptop-hp.mail-host-address-is-not-set> (view parent)
DKIM signature
missing
Download raw message
Osama Rebach <osamarebach@gmail.com> writes:

> Thanks, running the "init_speedup" branch resolved the issue.
>
> Now running (detached-init) with 250 sessions:
>   (0.17904190499999997 1 0.02780058099999999)

Nice! Then I will merge this into the main branch, thanks for the help :)
Reply to thread Export thread (mbox)