-
Notifications
You must be signed in to change notification settings - Fork 1.1k
perf: reduce memory usage #1812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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>
There was a problem hiding this 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.Collectwith efficientCopy()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>
|
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! |
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>
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:
After ~5min of inactivity main x this branch:
After then sending "hi" main x this branch:
After ~5m of inactivity again main x this branch: