Skip to content

Conversation

@caarlos0
Copy link
Member

@caarlos0 caarlos0 commented Jan 9, 2026

back ported #1810 to be based on main

Several performance-related changes to reduce memory usage.

In some platforms it might reduce initial memory usage up to 50% (on my machine, from ~200mb to ~100mb).

see each commit for more details.

Some stats

Just opened main x this branch:
CleanShot 2026-01-09 at 13 38 04@2x
After ~5min of inactivity main x this branch:
CleanShot 2026-01-09 at 13 41 52@2x
After then sending "hi" main x this branch:
CleanShot 2026-01-09 at 13 42 11@2x
After ~5m of inactivity again main x this branch:
CleanShot 2026-01-09 at 13 43 24@2x

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Previous version was doing way too many allocations, latest versions are better in that regard.

Total allocations dropped from ~317MB to ~88MB - a ~72% reduction in total allocations.

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
the library we are using uses wazero, and will take 70+mb of ram on
init.

modernc/sqlite is not supported on all platforms we currently ship to,
so this duplicates the connect.go file for each driver with the
according build tags.

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
@caarlos0 caarlos0 self-assigned this Jan 9, 2026
Copilot AI review requested due to automatic review settings January 9, 2026 16:34
@caarlos0 caarlos0 requested a review from a team as a code owner January 9, 2026 16:34
@caarlos0 caarlos0 requested review from kujtimiihoxha and meowgorithm and removed request for a team January 9, 2026 16:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements several performance optimizations to reduce memory usage, potentially achieving up to 50% reduction in initial memory usage (from ~200MB to ~100MB on some platforms). The changes focus on reducing unnecessary allocations, caching frequently computed values, and optimizing database driver selection.

Key changes include:

  • Introducing cached diagnostic counts in LSP clients to avoid recomputing on every UI render
  • Moving regex pattern compilation to package-level variables to prevent repeated allocations
  • Replacing maps.Collect with efficient Copy() methods to reduce intermediate allocations
  • Adding platform-specific database driver selection (modernc.org/sqlite vs ncruces/go-sqlite3)

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/lsp/client.go Adds DiagnosticCounts struct and cached counting mechanism with version tracking
internal/tui/components/lsp/lsp.go Refactors diagnostic counting to use the new GetDiagnosticCounts() method
internal/tui/components/chat/header/header.go Simplifies error counting using GetDiagnosticCounts()
internal/oauth/copilot/client.go Moves regex compilation to package level to avoid repeated allocations
internal/agent/tools/fetch_helpers.go Moves regex compilation to package level for markdown cleanup
internal/csync/maps.go Adds Copy() method and refactors Seq2() to use it
internal/csync/versionedmap.go Adds Copy() method for efficient map copying
internal/app/lsp_events.go Uses Copy() instead of maps.Collect()
internal/agent/tools/mcp/init.go Uses Copy() instead of maps.Collect()
internal/db/connect.go Refactors to use platform-specific openDB() implementations
internal/db/connect_modernc.go New file with modernc.org/sqlite implementation for common platforms
internal/db/connect_ncruces.go New file with ncruces/go-sqlite3 implementation for other platforms
go.mod Updates charmtone dependency and adds modernc.org/sqlite
go.sum Updates checksums for dependency changes
Taskfile.yaml Changes run task to build then execute instead of using go run

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
@caarlos0
Copy link
Member Author

caarlos0 commented Jan 9, 2026

and yes, build is working fine:

$ goreleaser build --clean --snapshot --skip=before --parallelism=2
  • by using this software you agree with its EULA, available at https://goreleaser.com/eula
  • running goreleaser v2.13.2
    • importing charmbracelet/meta/main/notarize.yaml
  • skipping before and validate...
  • cleaning distribution directory
  • loading environment variables
    • using token from $GITHUB_TOKEN
  • getting and validating git state
    • git state                                      commit=b821ccedb9df9cf8dd48beaf9205bb9349da4142 branch=mem-improvements-main current_tag=v0.31.0 previous_tag=v0.30.3 dirty=false
    • pipe skipped or partially skipped              reason=validation is disabled
  • parsing tag
  • setting defaults
    • brews is being phased out in favor of homebrew_casks, check https://goreleaser.com/deprecations#brews for more info
  • snapshotting
    • building snapshot...                           version=0.0.0-1767977809
  • ensuring distribution directory
  • setting up metadata
  • writing release metadata
  • loading go mod information
  • build prerequisites
  • building binaries
    • building                                       binary=dist/crush_linux_arm64_v8.0/crush
    • building                                       binary=dist/crush_linux_amd64_v1/crush
    • building                                       binary=dist/crush_linux_386_sse2/crush
    • building                                       binary=dist/crush_linux_arm_7/crush
    • building                                       binary=dist/crush_darwin_amd64_v1/crush
    • building                                       binary=dist/crush_darwin_arm64_v8.0/crush
    • building                                       binary=dist/crush_windows_amd64_v1/crush.exe
    • building                                       binary=dist/crush_windows_arm64_v8.0/crush.exe
    • building                                       binary=dist/crush_windows_386_sse2/crush.exe
    • building                                       binary=dist/crush_freebsd_amd64_v1/crush
    • building                                       binary=dist/crush_freebsd_arm64_v8.0/crush
    • building                                       binary=dist/crush_freebsd_386_sse2/crush
    • building                                       binary=dist/crush_freebsd_arm_7/crush
    • building                                       binary=dist/crush_openbsd_amd64_v1/crush
    • building                                       binary=dist/crush_openbsd_arm64_v8.0/crush
    • building                                       binary=dist/crush_openbsd_386_sse2/crush
    • building                                       binary=dist/crush_openbsd_arm_7/crush
    • building                                       binary=dist/crush_netbsd_amd64_v1/crush
    • building                                       binary=dist/crush_netbsd_arm64_v8.0/crush
    • building                                       binary=dist/crush_netbsd_386_sse2/crush
    • building                                       binary=dist/crush_netbsd_arm_7/crush
    • building                                       binary=dist/crush_android_arm64_v8.0/crush
      • took: 4m23s
  • sign & notarize macOS binaries
    • pipe skipped or partially skipped              reason=disabled
  • setting up metadata
  • storing artifacts metadata
  • build succeeded after 4m23s
  • thanks for using GoReleaser Pro!

@caarlos0 caarlos0 changed the title Mem improvements main perf: reduce memory usage Jan 9, 2026
@caarlos0 caarlos0 merged commit d1382bb into main Jan 9, 2026
15 checks passed
@caarlos0 caarlos0 deleted the mem-improvements-main branch January 9, 2026 17:21
BrunoKrugel pushed a commit to BrunoKrugel/crush that referenced this pull request Jan 9, 2026
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
aleksclark pushed a commit to aleksclark/crush that referenced this pull request Jan 12, 2026
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
puffitos pushed a commit to puffitos/crush that referenced this pull request Jan 13, 2026
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
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.

3 participants