Skip to content

Bump go-runewidth to v0.0.30 for faster startup - #14577

Merged
williammartin merged 1 commit into
trunkfrom
williammartin-profile-startup-cost
Oct 2, 2026
Merged

williammartin merged 1 commit into
trunkfrom
williammartin-profile-startup-cost

Conversation

@williammartin

@williammartin williammartin commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Description

Every gh invocation pays for the init() functions of every package linked into the binary, whether or not the command uses them. github.com/mattn/go-runewidth (an indirect dependency via charm.land/bubbles/v2, used by the prompter) was bumped from v0.0.24 to v0.0.27 as part of #14249 (the charm.land/bubbles/v2 2.1.1 → 2.2.0 bump). v0.0.27 eagerly fills a 2.2MB rune-width lookup table ([2][0x110000]byte) in init(), which takes about 12ms. That was roughly a third of the total startup time of gh --version.

Upstream fixed this in v0.0.30 by building the table lazily on first lookup (mattn/go-runewidth#104), so importing the package is nearly free again. This PR bumps the indirect dependency to v0.0.30. No other modules change.

How did you test this change?

I built bin/gh with make on macOS (arm64) before and after the bump. I timed it with hyperfine -N --warmup 5 -r 60 './bin/gh --version', with GH_NO_UPDATE_NOTIFIER=1 set:

Mean time
Before (go-runewidth v0.0.27) 38.0 ms ± 2.8 ms
After (go-runewidth v0.0.30) 25.3 ms ± 2.2 ms

I also ran GODEBUG=inittrace=1 ./bin/gh --version to see the package's init cost directly:

  • Before: init github.com/mattn/go-runewidth ... 12 ms clock, 18776 bytes, 44 allocs
  • After: init github.com/mattn/go-runewidth ... 0.014 ms clock, 0 bytes, 0 allocs

Key points

  • With this change, the width table is built on the first width lookup instead of at startup. Only commands that measure text width, such as prompts, pay that cost, and they pay it only when it's needed.
  • The dependency stays marked // indirect. It can't move backwards unless a direct dependency requires an older version.

Notes for reviewers

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @williammartin will read and reply directly. Name the account.
  • An agent will draft replies and @williammartin will read them before they are posted.
  • Nobody has explicitly committed to replying.

v0.0.27 eagerly built a 2.2MB width lookup table in init(),
adding ~12ms to every gh invocation. v0.0.30 builds it lazily.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 15:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The valid dependency update is narrowly scoped and consistent with the documented upstream startup fix.

Review effort: Balanced
Findings: None

What changed in this PR

Bumps go-runewidth to restore faster GitHub CLI startup through lazy width-table initialization.

Changes:

  • Updates the indirect dependency from v0.0.27 to v0.0.30.
  • Refreshes corresponding module checksums.
File Description
go.mod Updates the indirect dependency version.
go.sum Records v0.0.30 checksums.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@williammartin
williammartin marked this pull request as ready for review October 2, 2026 16:01
@williammartin
williammartin requested a review from a team as a code owner October 2, 2026 16:01
@williammartin
williammartin requested review from BagToad and tidy-dev and removed request for tidy-dev October 2, 2026 16:01

@BagToad BagToad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 🔥

@williammartin
williammartin merged commit 6fc1c29 into trunk Oct 2, 2026
40 checks passed
@williammartin
williammartin deleted the williammartin-profile-startup-cost branch October 2, 2026 16:05

@mohm04725-ux mohm04725-ux left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

4 participants