Skip to content

perf(cache): replace MarshalIndent with Marshal in local cache#164

Merged
SantiagoDePolonia merged 1 commit intomainfrom
perf/cache-marshal-indent
Mar 22, 2026
Merged

perf(cache): replace MarshalIndent with Marshal in local cache#164
SantiagoDePolonia merged 1 commit intomainfrom
perf/cache-marshal-indent

Conversation

@SantiagoDePolonia
Copy link
Copy Markdown
Contributor

@SantiagoDePolonia SantiagoDePolonia commented Mar 22, 2026

Summary

  • Replace json.MarshalIndent with json.Marshal in local model cache Set() — the cache file is only read by the application, never by humans
  • Eliminates unnecessary buffer growth from indentation formatting on every cache refresh cycle
  • Identified via pprof profiling: SaveToCacheMarshalIndent accounted for ~7.8 MB of allocations across 500 requests

Test plan

  • Existing TestLocalCache tests pass (round-trip Get/Set verified)
  • All pre-commit hooks pass (unit tests, golangci-lint)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance
    • Optimized internal cache storage to reduce file size and improve efficiency.

The local model cache file is never read by humans — only by the
application on startup. MarshalIndent allocates extra buffer space for
indentation, adding unnecessary GC pressure on every cache refresh cycle.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ffe38f0d-e2e8-4026-be48-8f5cb6c9af8a

📥 Commits

Reviewing files that changed from the base of the PR and between 3e6aa16 and 2c015dd.

📒 Files selected for processing (1)
  • internal/cache/modelcache/local.go

📝 Walkthrough

Walkthrough

The LocalCache.Set method now serializes the ModelCache using compact JSON formatting instead of pretty-printed JSON, reducing the on-disk cache file size while preserving all existing behavior and error handling.

Changes

Cohort / File(s) Summary
Cache Serialization Format
internal/cache/modelcache/local.go
Changed JSON serialization from json.MarshalIndent (pretty-printed) to json.Marshal (compact) for ModelCache storage, reducing file size without altering functionality.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A compact JSON hop,
No spaces, no padding, no fluff—
Smaller files that don't stop,
The cache just got neat enough! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing MarshalIndent with Marshal in the local cache for performance optimization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/cache-marshal-indent

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@SantiagoDePolonia SantiagoDePolonia merged commit 3e74650 into main Mar 22, 2026
16 checks passed
@SantiagoDePolonia SantiagoDePolonia deleted the perf/cache-marshal-indent branch April 4, 2026 11:49
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.

1 participant