Speed up shell startup 9x (1.9s → 0.2s)
Lazy-load Intel oneAPI setvars.sh (~1.5s) via wrapper functions that source the environment on first use of icc/icx/ifort/etc. Cache all shell completion outputs to ~/.cache/bash.d/ so they are sourced from disk instead of regenerated via subprocess on every shell start. Cache invalidates automatically when the tool binary is updated. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a9875dceec
commit
6a00847d4e
11 changed files with 83 additions and 23 deletions
50
20-oneapi
50
20-oneapi
|
|
@ -1,13 +1,45 @@
|
|||
# shellcheck shell=bash
|
||||
# Intel oneAPI toolkit — source the environment setup if installed
|
||||
# shellcheck disable=SC1090
|
||||
# Intel oneAPI toolkit — lazy-loaded to avoid ~1.5s startup penalty.
|
||||
# The full environment is sourced on first use of any Intel compiler/tool.
|
||||
# To load manually: _load_oneapi
|
||||
|
||||
ONEAPI_SETVARS="/opt/intel/oneapi/setvars.sh"
|
||||
|
||||
if [[ -f "$ONEAPI_SETVARS" ]]; then
|
||||
. "$ONEAPI_SETVARS" --force > /dev/null
|
||||
if [[ -n "$ONEAPI_ROOT" ]]; then
|
||||
case ":${LD_LIBRARY_PATH}:" in
|
||||
*":${ONEAPI_ROOT}/lib:"*) ;;
|
||||
*) export LD_LIBRARY_PATH="${ONEAPI_ROOT}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" ;;
|
||||
esac
|
||||
fi
|
||||
_load_oneapi() {
|
||||
# Guard against double-loading
|
||||
if [[ "${_ONEAPI_LOADED:-0}" -eq 1 ]]; then
|
||||
return
|
||||
fi
|
||||
_ONEAPI_LOADED=1
|
||||
|
||||
# Remove the lazy-load wrappers before sourcing
|
||||
local _cmd
|
||||
for _cmd in icc icpc icx icpx ifort ifx dpcpp; do
|
||||
unset -f "$_cmd" 2>/dev/null
|
||||
done
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
. "$ONEAPI_SETVARS" --force > /dev/null
|
||||
|
||||
if [[ -n "$ONEAPI_ROOT" ]]; then
|
||||
case ":${LD_LIBRARY_PATH}:" in
|
||||
*":${ONEAPI_ROOT}/lib:"*) ;;
|
||||
*) export LD_LIBRARY_PATH="${ONEAPI_ROOT}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
# Create wrapper functions for common Intel tools that trigger lazy-load
|
||||
_oneapi_lazy_wrap() {
|
||||
local cmd="$1"
|
||||
# shellcheck disable=SC2139
|
||||
eval "${cmd}() { _load_oneapi; command ${cmd} \"\$@\"; }"
|
||||
}
|
||||
|
||||
for _oneapi_cmd in icc icpc icx icpx ifort ifx dpcpp; do
|
||||
_oneapi_lazy_wrap "$_oneapi_cmd"
|
||||
done
|
||||
unset -f _oneapi_lazy_wrap
|
||||
unset _oneapi_cmd
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue