Bug 2315577 - Opening an interactive shell is slow because of /etc/zshrc
Summary: Opening an interactive shell is slow because of /etc/zshrc
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: Lmod
Version: 40
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Orion Poplawski
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-09-29 20:27 UTC by Nadav Har'El
Modified: 2024-10-12 02:56 UTC (History)
7 users (show)

Fixed In Version: Lmod-8.7.49-1.fc41 Lmod-8.7.49-1.fc40 Lmod-8.7.49-1.fc39 Lmod-8.7.49-1.el8 Lmod-8.7.49-1.el9
Clone Of:
Environment:
Last Closed: 2024-10-12 00:18:07 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Nadav Har'El 2024-09-29 20:27:28 UTC
Every time I open a new a new terminal window, I see my login shell (zsh) visibly taking time to present the first prompt. "time zsh -i /dev/null" shows that starting an *interactive* shell takes as much as half a second (this is just true for an interactive shell).

I traced (literally, with strace) the slowness to Fedora's /etc/zshrc executing all the files in /etc/profile.d. As soon as I removed /etc/zshrc the entire slowness was gone - an interactive shell now starts in about 0.03 seconds, which appears immediate.

In the old days, the whole point of the difference between zprofile and zshrc is that zprofile is run only on the **login** shell, and does potentially slow initializations and well as set up environment variables which can be inherited, and zshrc (which is executed again and again in every interactive shell) only sets up a small number of things that cannot be inherited like shell functions and shell options and aliases - but /etc/profile.d does NOT normally have those things. But I see in Fedora it does - many of the files I have in /etc/profile.d do have functions and aliases in them :-(

So Fedora completely goes again this classic separation. I don't know if was deliberate or maybe Gnome forced youyr hand by making it impossible to run the inheritable zprofile or profile.d once (something that once upon a time an XSession file would do), so this is why we're forced to run it in every interactive shell separately? Is this documentated anywhere?

If this is deliberate, I think /etc/profile.d should go on a serious diet, or somehow /etc/zshrc should be more selective in what it runs. I'm not sure exactly which of the specific files in my /etc/profile.d is particularly slow - or it's just the fact that there are many of them.

I'm not sure this is at all a zsh-specific problem. I notice "bash -i" is also surprising slow, possibly for the same reason.

Reproducible: Always

Steps to Reproduce:
time zsh -i </dev/null
Actual Results:  
0.5 seconds

Expected Results:  
0.03 seconds

Comment 1 Nadav Har'El 2024-09-29 22:41:02 UTC
By some experimentation, I discovered that the slowest part of /etc/profile.d, accounting for around 80% (!) of all the slowness, came from the "Lmod" package.
I never heard of the Lmod package, nor remember deliebrately installing it.
I uninstalled it, and now the interactive log in time is down to around 0.06 seconds, which is a huge visible improvement.

So I'm tempted to say this is a bug in the Lmod package, not the zsh package - as it introduces this unnecessary slowness not just to zsh but also to bash.

Comment 2 Nadav Har'El 2024-09-29 22:52:12 UTC
I found this page: https://utcc.utoronto.ca/~cks/space/blog/linux/Fedora40LoginStallWhy. It suggests that lmod's /usr/share/lmod/lmod/init/bash (and probably also zsh) has an unknown command which causes some slow "search for unknown command" machinery to be used. I verified that indeed trying to run an unknown command takes about 0.2 seconds on my machine - much of the slowdown I noticed.

If this is true, than the immediate cause of the interactive-shell-startup slowness is this unknown command in lmod's init script that runs in every interactive shell.
This can probably be easily fix - this script shouldn't try to run an unknown command. 

But additional questions can be asked:
1. Why does installing lmod need to initialize things in interactive shells?
2. Why does the very slow command-not-found is applied in /etc/zshrc and /etc/bashrc? If it's a fact of life, can it at least be temporary disabled in /etc/z,bashhrc?
3. Why does /etc/profile.d/* run at all in interactive, non-login shells. But I think I gave up on hoping this would be fixed - it goes against every principle of the original Unix shell design, but it seems too deeply engrained in Fedora to fix now.

Comment 3 Fedora Update System 2024-10-03 01:30:12 UTC
FEDORA-EPEL-2024-c2b8a70541 (Lmod-8.7.49-1.el8) has been submitted as an update to Fedora EPEL 8.
https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2024-c2b8a70541

Comment 4 Fedora Update System 2024-10-03 01:30:15 UTC
FEDORA-2024-8b931bc304 (Lmod-8.7.49-1.fc41) has been submitted as an update to Fedora 41.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-8b931bc304

Comment 5 Fedora Update System 2024-10-03 01:30:18 UTC
FEDORA-2024-f07875c71c (Lmod-8.7.49-1.fc39) has been submitted as an update to Fedora 39.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-f07875c71c

Comment 6 Fedora Update System 2024-10-03 01:30:21 UTC
FEDORA-EPEL-2024-37543a9986 (Lmod-8.7.49-1.el9) has been submitted as an update to Fedora EPEL 9.
https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2024-37543a9986

Comment 7 Fedora Update System 2024-10-03 01:30:24 UTC
FEDORA-2024-476878f60d (Lmod-8.7.49-1.fc40) has been submitted as an update to Fedora 40.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-476878f60d

Comment 8 Fedora Update System 2024-10-04 01:40:14 UTC
FEDORA-2024-476878f60d has been pushed to the Fedora 40 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2024-476878f60d`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2024-476878f60d

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 9 Fedora Update System 2024-10-04 02:17:58 UTC
FEDORA-2024-f07875c71c has been pushed to the Fedora 39 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2024-f07875c71c`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2024-f07875c71c

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 10 Fedora Update System 2024-10-04 02:29:45 UTC
FEDORA-EPEL-2024-c2b8a70541 has been pushed to the Fedora EPEL 8 testing repository.

You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2024-c2b8a70541

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 11 Fedora Update System 2024-10-04 02:38:11 UTC
FEDORA-EPEL-2024-37543a9986 has been pushed to the Fedora EPEL 9 testing repository.

You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2024-37543a9986

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 12 Fedora Update System 2024-10-04 02:55:59 UTC
FEDORA-2024-8b931bc304 has been pushed to the Fedora 41 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2024-8b931bc304`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2024-8b931bc304

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 13 Fedora Update System 2024-10-12 00:18:07 UTC
FEDORA-2024-8b931bc304 (Lmod-8.7.49-1.fc41) has been pushed to the Fedora 41 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 14 Fedora Update System 2024-10-12 01:40:23 UTC
FEDORA-2024-476878f60d (Lmod-8.7.49-1.fc40) has been pushed to the Fedora 40 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 15 Fedora Update System 2024-10-12 01:50:56 UTC
FEDORA-2024-f07875c71c (Lmod-8.7.49-1.fc39) has been pushed to the Fedora 39 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 16 Fedora Update System 2024-10-12 02:43:49 UTC
FEDORA-EPEL-2024-c2b8a70541 (Lmod-8.7.49-1.el8) has been pushed to the Fedora EPEL 8 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 17 Fedora Update System 2024-10-12 02:56:39 UTC
FEDORA-EPEL-2024-37543a9986 (Lmod-8.7.49-1.el9) has been pushed to the Fedora EPEL 9 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.