fix: disable SQLite mmap to prevent memory growing with DB size#22428
Open
jiangliang79 wants to merge 1 commit intoanomalyco:devfrom
Open
fix: disable SQLite mmap to prevent memory growing with DB size#22428jiangliang79 wants to merge 1 commit intoanomalyco:devfrom
jiangliang79 wants to merge 1 commit intoanomalyco:devfrom
Conversation
Bun's bundled SQLite enables memory-mapped I/O by default, which maps the entire DB file into the process address space. This causes the process footprint to grow proportionally with the DB file size regardless of actual data access patterns. Observed on macOS ARM64: a 1.1 GB opencode.db results in ~1.8 GB of IOAccelerator memory in the process footprint snapshot. Setting PRAGMA mmap_size = 0 restores SQLite's official default behavior, bounding SQLite's memory contribution to the cache_size limit (~64 MB). The performance impact is negligible — sub-millisecond extra latency on cache misses, dwarfed by LLM API call latency.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
zhumengzhu
pushed a commit
to zhumengzhu/opencode
that referenced
this pull request
Apr 14, 2026
Two independent fixes for memory/stability issues: 1. SQLite mmap_size = 0: Bun enables mmap by default, causing the DB file size to be mapped directly into the process address space. A 1.1 GB DB results in ~1.8 GB of additional memory footprint. Disabling mmap keeps memory usage proportional to active cache, not file size. (ref anomalyco#22428) 2. GlobalBus.setMaxListeners(100): each SSE connection registers one listener on GlobalBus and removes it on disconnect. The default Node.js limit of 10 triggers MaxListenersExceededWarning during normal usage with multiple concurrent connections. 100 is a safe upper bound without hiding real leaks. (ref anomalyco#22422) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #22429
Type of change
What does this PR do?
Bun's bundled SQLite enables memory-mapped I/O by default, which maps the entire DB file into the process address space. This causes the process footprint to grow proportionally with the DB file size regardless of actual data access patterns.
Observed on macOS ARM64: a 1.1 GB opencode.db results in ~1.8 GB of IOAccelerator memory in the process footprint snapshot.
Setting PRAGMA mmap_size = 0 restores SQLite's official default behavior, bounding SQLite's memory contribution to the cache_size limit (~64 MB). The performance impact is negligible — sub-millisecond extra latency on cache misses, dwarfed by LLM API call latency.
How did you verify your code works?
Took a footprint snapshot of the opencode process on macOS ARM64 before and after the change with a 1.1 GB DB. The IOAccelerator region (SQLite mmap pages) dropped from ~1.8 GB to negligible. Functional behavior is unchanged — mmap only affects how pages are loaded from disk, not what data SQLite returns.
Checklist