Skip to content

Add bash profile startup time profiling capability#13

Merged
oinume merged 1 commit intomasterfrom
claude/profile-bash-startup-fpZU9
Feb 11, 2026
Merged

Add bash profile startup time profiling capability#13
oinume merged 1 commit intomasterfrom
claude/profile-bash-startup-fpZU9

Conversation

@oinume
Copy link
Owner

@oinume oinume commented Feb 11, 2026

Summary

Added an optional profiling system to .bash_profile that measures and logs the startup time of different initialization sections. This helps identify performance bottlenecks during shell startup.

BASH_PROFILE_PROFILING=1

Key Changes

  • Profiling Framework: Added a conditional profiling system that can be enabled via BASH_PROFILE_PROFILING=1 bash -l
  • Time Measurement: Implemented _bp_get_ms() function with fallback support for:
    • EPOCHREALTIME (preferred, highest precision)
    • gdate (GNU date, fallback for macOS)
    • Standard date command (lowest precision fallback)
  • Logging Function: Added _bp_log() that prints cumulative time since profile start and delta time since last log point
  • Instrumentation: Added _bp_log calls throughout the profile to measure initialization time of major sections:
    • Prompt/history setup
    • Homebrew initialization
    • Bash completion
    • Bash-it framework
    • FZF configuration
    • Bash-powerline
    • Tmuxinator
    • Git completion
    • Language runtime managers (rbenv, JDK, nvm, mise)
    • Other tools (direnv, wtp, pnpm, google-cloud-sdk)
  • Cleanup: Profiling functions and variables are unset at the end when profiling is enabled
  • Minor Fixes: Fixed trailing whitespace issues in existing code

Implementation Details

  • Profiling is completely opt-in and has zero overhead when disabled
  • Output is sent to stderr to avoid interfering with stdout
  • Uses ANSI color codes (yellow) for visual distinction of profile output
  • Provides both cumulative and incremental timing information for each section

result

BASH_PROFILE_PROFILING=1 bash -l
[profile]     15 ms (+  15 ms) prompt/history
[profile]     74 ms (+  59 ms) brew --prefix
[profile]     84 ms (+  10 ms) .bash_local
[profile]     96 ms (+  12 ms) bash-completion
[profile]    750 ms (+ 654 ms) bash-it
[profile]    796 ms (+  46 ms) fzf
[profile]    803 ms (+   7 ms) bash-powerline
[profile]    811 ms (+   8 ms) tmuxinator
[profile]    818 ms (+   7 ms) completion (git)
[profile]    833 ms (+  15 ms) google-cloud-sdk
[profile]    986 ms (+ 153 ms) rbenv
[profile]   1005 ms (+  19 ms) JDK (java_home)
[profile]   1489 ms (+ 484 ms) nvm
[profile]   1525 ms (+  36 ms) mise
[profile]   1544 ms (+  19 ms) wtp
[profile]   1560 ms (+  16 ms) direnv
[profile]   1566 ms (+   6 ms) nvm bash_completion
[profile]   1574 ms (+   8 ms) ===== TOTAL =====

https://claude.ai/code/session_01KUTPUqiighqZpzEWb3mdVK

Enable with BASH_PROFILE_PROFILING=1 bash -l to measure time spent
in each section of .bash_profile during shell startup. Uses
EPOCHREALTIME (bash 5+) for ms precision with gdate/date fallback.

https://claude.ai/code/session_01KUTPUqiighqZpzEWb3mdVK
@oinume oinume marked this pull request as ready for review February 11, 2026 03:23
@oinume oinume merged commit b62bd91 into master Feb 11, 2026
@oinume oinume deleted the claude/profile-bash-startup-fpZU9 branch February 11, 2026 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants